예제 #1
0
        private void GetYelp(IPInfo ipInfo)
        {
            try
            {
                //Consumer Key, Consumer Secret, Token, Token Secret
                string sTileHeight = "whTileHeightSmall";
                string sTerm = "food";
                string sKeys = GetKeys("Yelp");
                string[] KeyList = sKeys.Split(',');
                string sLocation = ipInfo.city + ", " + ipInfo.region;

                YelpAPIClient YelpClient = new YelpAPIClient(KeyList[0], KeyList[1], KeyList[2], KeyList[3]);

                JObject YelpResponse = YelpClient.Search(sTerm, sLocation);

                JArray Businesses = (JArray)YelpResponse.GetValue("businesses");

                foreach(var Business in Businesses)
                {
                    var YelpBusiness = (YelpAPIClient.Business)Business.ToObject(typeof(YelpAPIClient.Business));

                    AddContentTile("Yelp",
                        "<a href=" + YelpBusiness.mobile_url + "/>" + YelpBusiness.name + "</a><br/>" +
                        "Rating: " + YelpBusiness.rated + ".  " +
                        "Number of ratings: " + YelpBusiness.review_count + ".",
                        sTileHeight);
                }

                YelpClient = null;
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #2
0
        private void GetWeather(IPInfo ipInfo)
        {
            try
            {
                string sTileHeight = "whTileHeightSmall";
                XPathDocument xDoc = new XPathDocument("http://xml.weather.yahoo.com/forecastrss?p=" + ipInfo.postal);
                XPathNavigator xNavigator;
                XmlNamespaceManager xNameSpace;
                XPathNodeIterator xNodes;
                XPathNavigator xNode;
                string sBody = "";

                xNavigator = xDoc.CreateNavigator();

                xNameSpace = new XmlNamespaceManager(xNavigator.NameTable);
                xNameSpace.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
                xNodes = xNavigator.Select("/rss/channel/item/title", xNameSpace);

                while (xNodes.MoveNext())
                {
                    xNode = xNodes.Current;
                    sBody = xNode.InnerXml.ToString() + "<br/>";
                }

                xNodes = xNavigator.Select("/rss/channel/item/yweather:condition", xNameSpace);

                //Basic: Temp and Condition
                while (xNodes.MoveNext())
                {
                    xNode = xNodes.Current;
                    sBody += xNode.GetAttribute("temp", xNameSpace.DefaultNamespace) + "f and ";

                    sBody += xNode.GetAttribute("text", xNameSpace.DefaultNamespace);
                    AddContentTile("weather", sBody, sTileHeight);
                }

                //Sunrise and Sunset
                xNodes = xNavigator.Select("/rss/channel/yweather:astronomy", xNameSpace);
                while(xNodes.MoveNext())
                {
                    xNode = xNodes.Current;
                    AddContentTile("weather",
                        "Sunrise: " + xNode.GetAttribute("sunrise", xNameSpace.DefaultNamespace) + "<br/>" +
                        "Sunset: " + xNode.GetAttribute("sunset", xNameSpace.DefaultNamespace),
                        sTileHeight);
                }

                //extended forcast
                xNodes = xNavigator.Select("/rss/channel/item/yweather:forecast", xNameSpace);
                while (xNodes.MoveNext())
                {
                    xNode = xNodes.Current;
                    AddContentTile("weather", xNode.GetAttribute("day", xNameSpace.DefaultNamespace) + ": " + xNode.GetAttribute("text", xNameSpace.DefaultNamespace), sTileHeight);
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #3
0
        private void GetWikipedia(IPInfo ipInfo)
        {
            try
            {
                string sTileHeight = "whTileHeightSmall";
                string[] sLocation = ipInfo.loc.ToString().Split(',');
                string sURL = "https://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=10000&gscoord=" + sLocation[0] + "%7c" + sLocation[1] + "&format=json";

                using (WebClient client = new WebClient())
                {
                    var json = client.DownloadString(sURL);
                    WikipediaObject Articles = JsonConvert.DeserializeObject<WikipediaObject>(json);

                    foreach(GeoSearchResult Article in Articles.Query.GeoSearch)
                    {
                        AddContentTile("Wikipedia", "<a href=" + "http://en.wikipedia.org/?curid=" + Article.PageId + ">" + Article.Title + "</a>", sTileHeight);
                    }
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #4
0
        private void GetTwitter(IPInfo ipInfo)
        {
            try
            {
                //Consumer Key, Consumer Secret, Token, Token Secret
                string sKeys = GetKeys("Twitter");
                string[] sLocation = ipInfo.loc.ToString().Split(',');

                 //ITwitter twitter = new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);

                //IList<Place> results = twitter.GeoOperations.SearchAsync(Convert.ToDouble(sLocation[0]), Convert.ToDouble(sLocation[1])).Result;

                //IList<Place> RETURNS = twitter.GeoOperations.ReverseGeoCodeAsync(Convert.ToDouble(sLocation[0]), Convert.ToDouble(sLocation[1]), null, "10m").Result;

                //System.Threading.Tasks.Task<SearchResults> searchResults = twitter.SearchOperations.SearchAsync("#NYC");

                //var searchResults = twitter.SearchOperations.SearchAsync("#NYC", 10, 20);

                //var returnIT = searchResults.Wait(5000);

                //-----------------------------------------------
                Image WeatherIcon = new Image();
                WeatherIcon.CssClass = "HeaderIcon";
                WeatherIcon.ImageUrl = "images/" + "twitter" + ".png";

            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #5
0
        private void GetMTA(IPInfo ipInfo)
        {
            try
            {
                //Only New York City viewers should see this data
                if (ipInfo.city.ToLower() == "new york")
                {
                    string sTileHeight = "whTileHeightSmall";
                    XmlDocument xTransit = new XmlDocument();
                    xTransit.Load("http://mta.info/status/serviceStatus.txt");
                    var Lines = xTransit.GetElementsByTagName("name");
                    var Status = xTransit.GetElementsByTagName("status");

                    for (Int16 iTransit = 0; iTransit < Lines.Count; iTransit++)
                    {
                        if (Status[iTransit].InnerText.ToLower() != "good service")
                        {
                            AddContentTile("Transit", Lines[iTransit].InnerText + ": " + Status[iTransit].InnerText, sTileHeight);
                        }
                    }
                    xTransit = null;
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #6
0
        private void GetMap(IPInfo ipInfo)
        {
            try
            {
                string[] sLocation = ipInfo.loc.ToString().Split(',');
                var sMapSource = "http://maps.google.com?q=" + sLocation[0] + "," + sLocation[1] + "&z=15&output=embed";
                this.googlemap.Attributes.Add("src", sMapSource);

                this.WHCity.InnerHtml = "See whatz happn in<br />" + ipInfo.city + "!";
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #7
0
        private void GetFoursquare(IPInfo ipInfo)
        {
            try
            {
                //https://developer.foursquare.com/docs/venues/search
                //https://api.foursquare.com/v2/venues/search

                //EXAMPLE URL
                //https://api.foursquare.com/v2/venues/search?ll=40.7,-74&oauth_token=ZGUW45PQMIRNL04QMNFXV0BQGDRWKFNPU1L4WC34STBB0P1L&v=20151017

                //GETTING:  ex = {"The remote server returned an error: (401) Unauthorized."}
                //Likely do not have the correct value

                //ClientID, ClientSecret
                string sKeys = GetKeys("Foursquare");
                string[] KeyList = sKeys.Split(',');
                string sURL = "https://api.foursquare.com/v2/venues/search?ll=" + ipInfo.loc + "&oauth_token=" + KeyList[1] + "L&v=20151017";
                XmlDocument xFoursquare = new XmlDocument();
                xFoursquare.Load(sURL);
                //var Lines = xFoursquare.GetElementsByTagName("name");
                //var Status = xFoursquare.GetElementsByTagName("status");

                xFoursquare = null;
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
예제 #8
0
        private void GetArt(IPInfo ipInfo)
        {
            Int16 iArt = 0;
            try
            {
                if (ipInfo.city.ToLower() == "new york")
                {
                    string sTileHeight = "whTileHeightSmall";
                    string[] sLocation = ipInfo.loc.ToString().Split(',');
                    DateTime dtNow = DateTime.Now;
                    XmlDocument xArt = new XmlDocument();
                    xArt.Load("http://www.nycgovparks.org/bigapps/DPR_PublicArt_001.xml");

                    //TODO: Place a marker on the map for each found art.
                    var Names = xArt.GetElementsByTagName("name");
                    var Artists = xArt.GetElementsByTagName("artist");
                    var DateFroms = xArt.GetElementsByTagName("from_date");
                    var DateTos = xArt.GetElementsByTagName("to_date");
                    //var Descriptions = xArt.GetElementsByTagName("description");
                    var Lats = xArt.GetElementsByTagName("lat");
                    var Longs = xArt.GetElementsByTagName("lng");
                    double dMiles = 0;

                    for (iArt = 0; iArt < Names.Count; iArt++)
                    {
                        //Some pieces of data are coming back without Lat and Long.  Ignore those
                        if (Lats[iArt].InnerText.Trim().Length > 0 && Lats[iArt].InnerText.Trim().Length > 0)
                        {
                            //Only if it is currently on display
                            if (dtNow >= Convert.ToDateTime(DateFroms[iArt].InnerText) && dtNow < Convert.ToDateTime(DateTos[iArt].InnerText))
                            {
                                dMiles = distance(
                                Convert.ToDouble(sLocation[0]),
                                Convert.ToDouble(sLocation[1]),
                                Convert.ToDouble(Lats[iArt].InnerText),
                                Convert.ToDouble(Longs[iArt].InnerText));

                                //Only within a certain distance
                                if (dMiles < 11)
                                {
                                    AddContentTile("Art", Names[iArt].InnerText + " by " + Artists[iArt].InnerText, sTileHeight);
                                }
                            }
                        }
                    }

                    xArt = null;
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }