Created
June 18, 2013 05:58
-
-
Save pwhitdog/5802953 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity.Validation; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Net.Http; | |
using System.Web; | |
using Newtonsoft.Json; | |
namespace Casinos | |
{ | |
class Program | |
{ | |
static string BegingUrl = "https://maps.googleapis.com/maps/api/place/textsearch/json?query=casino+in+"; | |
static string LocationUrl = "San+Diego"; | |
static string EndUrl = "&sensor=false&key=AIzaSyC-D6wYKUIAPrKq6f4SwxjRCMwyEMRz5Ic"; | |
private static string FullUrl = BegingUrl + LocationUrl + EndUrl; | |
static PokerTrackingEntities db = new PokerTrackingEntities(); | |
static void Main() | |
{ | |
Runner().Wait(); | |
} | |
static async Task Runner() | |
{ | |
try | |
{ | |
// Create a New HttpClient object. | |
HttpClient client = new HttpClient(); | |
HttpResponseMessage response = await client.GetAsync(FullUrl); | |
response.EnsureSuccessStatusCode(); | |
string responseBody = await response.Content.ReadAsStringAsync(); | |
// Above three lines can be replaced with new helper method in following line | |
// string body = await client.GetStringAsync(uri); | |
dynamic dynObj = JsonConvert.DeserializeObject(responseBody); | |
foreach (var place in dynObj.results) | |
{ | |
Location location = new Location(); | |
location.Address = place.formatted_address; | |
location.Name = place.name; | |
foreach (var location1 in place.geometry) | |
{ | |
foreach (var geo in location1) | |
{ | |
location.Lat = geo.lat; | |
location.Lng = geo.lng; | |
} | |
} | |
string name = place.name; | |
try | |
{ | |
db.Locations.Add(location); | |
} | |
catch (DbEntityValidationException e) | |
{ | |
var blah = e; | |
throw; | |
} | |
System.Diagnostics.Debug.Write("Name" + ":" + name + " | |
"); | |
} | |
db.SaveChanges(); | |
//System.Diagnostics.Debug.Write(responseBody); | |
//Console.WriteLine(responseBody); | |
} | |
catch (HttpRequestException e) | |
{ | |
Console.WriteLine(" | |
Exception Caught!"); | |
Console.WriteLine("Message :{0} ", e.Message); | |
} | |
} | |
public class Casino | |
{ | |
public string Location { get; set; } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment