private static void AddVenueToDatabase(DistrictsInTownModelContainer dbContext, ForesquareVenue venue) { if (String.IsNullOrEmpty(venue.ZipCode)) return; dbContext.Places.Add(new Places { Location = DbGeography.FromText(String.Format("POINT ({0} {1})", venue.Longitude, venue.Latitude)), Keyword = venue.Keyword, Score = venue.Score, Source = venue.Source, Zip = venue.ZipCode }); }
private static void WriteVenue(ForesquareVenue venue) { Console.WriteLine("{0} {1},{2} {3} {4}", venue.Name, venue.Longitude, venue.Latitude, venue.ZipCode, venue.Score); }
private static async Task<ForesquareVenueResult> ExploreVenues(int offset, int limit, string near, string section, string[] categories, string keyword) { var httpClient = new HttpClient { BaseAddress = new Uri("https://api.foursquare.com/v2/") }; var response = await httpClient.GetStringAsync("venues/explore?client_id=" + CLIENT_ID + "&client_secret=" + CLIENT_SECRET + "&offset=" + offset + "&limit=" + limit + "&near=" + near + "§ion=" + section + "&v=20140101"); dynamic responseJson = JsonConvert.DeserializeObject(response); var result = new ForesquareVenueResult(); result.TotalResults = responseJson.response.totalResults; result.Venues = new List<ForesquareVenue>(); foreach (var group in responseJson.response.groups) { if (group.name != "recommended") continue; foreach (var groupItem in group.items) { var venue = groupItem.venue; try { if (!IsInCategory(venue.categories, categories)) continue; if (venue.rating < 7.0) continue; var venueResult = new ForesquareVenue { Name = venue.name, Longitude = venue.location.lng, Latitude = venue.location.lat, ZipCode = venue.location.postalCode, Keyword = keyword, Score = venue.rating, Source = "foursquare_" + venue.id }; result.Venues.Add(venueResult); } catch (Exception) { Console.WriteLine("Skipped {0}", venue.id); } } } return result; }