Exemplo n.º 1
0
 public static ProblemRanking[] LoadProblemRankings()
 {
     var s = new HttpClient().GetStringAsync("https://davar.icfpcontest.org/rankings.js").Result;
     JObject v = (JObject)JsonConvert.DeserializeObject(s.Substring(11));
     var problems = v["data"]["settings"].ToObject<ProblemRanking[]>();
     return problems;
 }
Exemplo n.º 2
0
        // Amazon UK price history can be checked in uk.camelcamelcamel.com, for example: http://uk.camelcamelcamel.com/Sennheiser-Professional-blocking-gaming-headset-Black/product/B00JQDOANK
        private static double? GetAmazonProductPrice(string p_amazonProductUrl)
        {
            string errorMessage = String.Empty;
            double price = 0.0;
            var webpage = new HttpClient().GetStringAsync(p_amazonProductUrl).Result;
            Utils.Logger.Info("HttpClient().GetStringAsync returned: " + ((webpage.Length > 100) ? webpage.Substring(0, 100) : webpage));

            // <span id="priceblock_ourprice" class="a-size-medium a-color-price">£199.95</span>
            string searchStr = @"id=""priceblock_ourprice"" class=""a-size-medium a-color-price"">";
            int startInd = webpage.IndexOf(searchStr);
            if (startInd == -1)
            {   // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
                Utils.Logger.Info($"searchString '{searchStr}' was not found.");
                return null;
            }
            int endInd = webpage.IndexOf('<', startInd + searchStr.Length);
            if (endInd == -1)
            {   // it is expected (not an exception), that sometimes Amazon changes its website, so we will fail. User will be notified.
                Utils.Logger.Info($"'<' after searchString '{searchStr}' was not found.");
                return null;
            }
            string priceStr = webpage.Substring(startInd + searchStr.Length + 1, endInd - (startInd + searchStr.Length + 1));
            if (!Double.TryParse(priceStr, out price))
            {
                Utils.Logger.Info($"{priceStr} cannot be parsed to Double.");
                return null;
            }
            return price;
        }