How to get a parental venue using a child venue - foursquare

Is there any way to get a parental venue using a child venue? For example, there's a Starbucks in an airport. I want to get the airport instead of the Starbucks. The Foursquare App has the section called "Other places inside xxx", so I thought there's a way to get it.
Any help would be much appreciated.

If you call the venue details API there will be a parent object in the response. I did a test with an airport terminal and saw.
GET https://api.foursquare.com/v2/venues/4c1fa175eac020a1c3614bc2
"parent": {
"id": "41059b00f964a520850b1fe3",
"name": "San Francisco International Airport (SFO) (San Francisco International Airport)",
"contact": {
"phone": "6508218211",
"formattedPhone": "(650) 821-8211",
"twitter": "flysfo",
"instagram": "flysfo",
"facebookUsername": "flySFO",
"facebookName": "San Francisco International Airport (SFO)"
}

Related

Azure Cognitive Search - Retrieve Search Score in Search Result

I am looking for a way to retrieve the search score in the search result (an index field value), similar to the other metadata fields like metadata_storage_name or metadata_storage_path. In the Indexer Definition, I tried retrieving the search score in the following way. Please correct me if I am missing anything or retrieving it the wrong way.
"fieldMappings": [
{
"sourceFieldName": "#search.score",
"targetFieldName": "search_score",
"mappingFunction": null
}
]
Search score is an attribute added to each search result in the search request response. Try issue a simple search request using your favourite REST client or Azure Poral. Below is an example of a response object. #search.score is what you're looking for.
"value": [
{
"#search.score": 7.3617697,
"HotelId": "21",
"HotelName": "Nova Hotel & Spa",
"Description": "1 Mile from the airport. Free WiFi, Outdoor Pool, Complimentary Airport Shuttle, 6 miles from the beach & 10 miles from downtown.",
"Category": "Resort and Spa",
"Tags": [
"pool",
"continental breakfast",
"free parking"
]
},
{
"#search.score": 2.5560288,
"HotelId": "25",
"HotelName": "Scottish Inn",
"Description": "Newly Redesigned Rooms & airport shuttle. Minutes from the airport, enjoy lakeside amenities, a resort-style pool & stylish new guestrooms with Internet TVs.",
"Category": "Luxury",
"Tags": [
"24-hour front desk service",
"continental breakfast",
"free wifi"
]
}]
Example is from here: https://learn.microsoft.com/en-us/azure/search/search-query-simple-examples#example-1-full-text-search
'#search.score' is not a field in an index, but a computation of each search result relevance scoring. If there is a match for the criteria of your search and a result returned, you can retrieve that value from the HTTP response with '#search.score'.
Field mappings on the other hand are used to map a field that is found in your data source and does not match the name you would like to use in the index, so you can map to the name you need.
For more information on the HTTP response of Search Documents REST API and search scoring, please visit:
https://learn.microsoft.com/rest/api/searchservice/search-documents and
https://learn.microsoft.com/azure/search/index-similarity-and-scoring

Insert multiple documents in index at once, using VScode Azure Cognitive Services extension. (Azure Search Service)

I want to insert multiple Documents at once into a Index in Azure Search Service. I am using VScode extension Azure Cognitive Services to insert as mentioned in their document.
Link to offical doc:
https://learn.microsoft.com/en-us/azure/search/search-get-started-vs-code
The official doc mentions the method to insert a single JSON i.e.Right Click Document->Create new document.
I tried to insert multiple JSON documents separated by comma (snipped attached below) using the above mentioned method, I get the error as expected:
Unexpected token, in JSON at position 915
My try to insert multiple documents in a single Create new document:
{
"HotelId": "4",
"HotelName": "Sublime Cliff Hotel",
"Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace.",
"Description_fr": null,
"Category": "Boutique",
"Tags": [
"concierge",
"view",
"24-hour front desk service"
],
"ParkingIncluded": true,
"LastRenovationDate": "1960-02-06T00:00:00Z",
"Rating": 4.6,
"Address": {
"StreetAddress": "7400 San Pedro Ave",
"City": "San Antonio",
"StateProvince": "TX",
"PostalCode": "78216",
"Country": "USA"
}
},
{
"HotelId": "5",
"HotelName": "Sublime Cliff Hotel",
"Description": "Sublime Cliff Hotel is located in the heart of the historic center of Sublime in an extremely vibrant and lively area within short walking distance to the sites and landmarks of the city and is surrounded by the extraordinary beauty of churches, buildings, shops and monuments. Sublime Cliff is part of a lovingly restored 1800 palace.",
"Description_fr": null,
"Category": "Boutique",
"Tags": [
"concierge",
"view",
"24-hour front desk service"
],
"ParkingIncluded": true,
"LastRenovationDate": "1960-02-06T00:00:00Z",
"Rating": 4.6,
"Address": {
"StreetAddress": "7400 San Pedro Ave",
"City": "San Antonio",
"StateProvince": "TX",
"PostalCode": "78216",
"Country": "USA"
}
}
Does anyone know any method to insert multiple documents at once in a index using VScode?
You can do the same thing using Postman by creating a POST request with the JSON passed in the body. This works for both single as well as multiple documents entry into the Index.
Link for official doc-
https://learn.microsoft.com/en-us/azure/search/search-get-started-rest

What libraries and concepts should I learn to parse data from a webpage?

I want to parse data from a website that has all universities listed in something like this
{
"web_pages": [
"http://www.marywood.edu"
],
"name": "Marywood University",
"alpha_two_code": "PA",
"state-province": null,
"domains": [
"marywood.edu"
],
"country": "United States"
}
How can I add each university name to a list and its country code too?
You should learn the basics of webbrowser, requests and bs4. You can also read Chapter 11 of "Automate The Boring Stuff with Python" by Al Swigart, which gives detailed explanations of everything needed.

How to delete specific object under document in DocumentDB?

I am using documentDB as backend for my project.
I have created a collection named ResellerCollection.
Under it I added document as Reseller with Id's assign to it.
Now under Reseller document I have added a list of Customer and now I wanted to delete customer of reseller document by specific Id.
My JSON generated in documentDB is as follow.
{
"id": "73386791-5895-4a56-9108-df4a773331fe",
"Name": "Nadeem",
"PrimaryContact": "1234",
"Address": "bhusari clny",
"City": "pune",
"State": "maharashtra",
"Country": "india",
"ZipCode": "222",
"Telephone": "45234343",
"Email": "abc#xyz.com",
"Website": "asdfsd.com",
"Customer": [
{
"id": "4acf3ca9-f9e4-4117-a471-7ce8f905baec",
"FullName": "Test Cust1",
"Company": "safds",
"JobTitle": "sadf",
"Email": "abcd#xyz.com",
"Address": "asdfsaf",
"City": "sdf",
"State": "sdf",
"Country": "sadf",
"ZipCode": "2343",
"Telephone": "45234343",
"MerchantID": "232",
"IdentificationNo": "2342343",
"IsActive": true,
"CustomerGroupID": "34",
"ResellerID": "73386791-5895-4a56-9108-df4a773331fe"
},
{
"id": "e0d6d099-3d5d-4776-9b84-14b7ae0b9911",
"FullName": "Test Cust2",
"Company": "safds",
"JobTitle": "sadf",
"Email": "abcd#xyz.com",
"Address": "asdfsaf",
"City": "sdf",
"State": "sdf",
"Country": "sadf",
"ZipCode": "2343",
"Telephone": "sadf",
"MerchantID": "232",
"IdentificationNo": "2342343",
"IsActive": true,
"CustomerGroupID": "34",
"ResellerID": "73386791-5895-4a56-9108-df4a773331fe"
}
],
"UserId": "f807f027-2e21-45b1-b786-e4d2b3d677cb",
"_rid": "+JBQAOQWHQENAAAAAAAAAA==",
"_self": "dbs/+JBQAA==/colls/+JBQAOQWHQE=/docs/+JBQAOQWHQENAAAAAAAAAA==/",
"_etag": "\"0a004764-0000-0000-0000-583bd8b50000\"",
"_attachments": "attachments/",
"_ts": 1480317104
}
Please suggest me how to write delete function for customer in MVC. Whether I should write delete for it to delete specific customer or whether I have to update the whole customer list?
Two ways of doing this.
Implement "AddCustomer" and "RemoveCustomer" stored procedures in DocumentDB. These stored procedures will read the reseller document, then append or remove the new customer passed in as argument. Then just call ExecuteStoredProcedureAsync within your controller.
Instead of the stored procedure approach, perform three steps within the controller. Read the document, make changes, and replace the document.
In both implementations, you'll probably want to use the ETag to perform a conditional write to avoid any clobbering across multiple clients/writers.
As Larry and David pointed out, you should also consider different JSON modeling options such as storing the customers data as separate documents, or by storing only the IDs within the array vs. all relevant customer data.
The only way to delete an element of an array (or any other change to the document) is to fetch the entire document, modify it, then create/upsert the entire document. You can do this client-side or in a stored procedure.
Try not to think of collections as tables in traditional databases or collections in MongoDB. I used to say, think of them as "partitions" but with partitioned collections, even that distinction is not useful. I use a single partitioned collection for everything now. I distinguish document types by having an element in each document: isReseller = true or isCustomer = true for your example. Alternatively, you can do type = 'Reseller' or type = 'Customer'. However, if the customer of one reseller is ever a reseller themselves, the former will allow you to add both is___ = true and the latter will not.
What David Makogon says is definitely a worry. Unless Resellers are restricted to a small number of Customers, you are better off storing them separately and having a foreign key link them. That way, deleting or adding one is a single step. However, getting the Reseller and all its Customers will be two round trips.

Comment blocks around JSON responses

I've noticed that some web applications return AJAX responses with JSON data embedded within a comment block. For example, this would be a sample response:
/*{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
"212 555-1234",
"646 555-4567"
]} */
What is the benefit of embedding the JSON data in a comment block? Is there some sort of security exploit which is avoided by doing this?
It's done to avoid a third party site hijacking your data using a <script> tag and overriding the Object constructor to grab the data as it is built.
When the JSON data is surrounded by comments, it no longer is directly executable via a <script> tag, and thereby "more secure".
See the PDF at http://www.fortifysoftware.com/servlet/downloads/public/JavaScript_Hijacking.pdf for more information (with examples)

Resources