Beispiel #1
0
        public static void PerformOilSlick()
        {
            Console.WriteLine("Reading weekly oil prices");
            var document = AgentHandler.Instance.PerformAction(new AgentSession(), new AgentAction("http://www.nyse.tv/crude-oil-price-history.htm", false));
            var match    = OilSlicker.Match(document.ResponseString);

            while (match.Success)
            {
                var month = match.Result("$1");
                var day   = match.Result("$2");
                var year  = match.Result("$3");
                var price = decimal.Parse(match.Result("$4"));

                var date = (DateTime) new DateTimeConverter().ConvertFromString(month + " " + day + ", " + year);

                if (DB.CrudeOils.Any(x => x.Day == date))
                {
                    Console.WriteLine(date.ToString("MM/dd/yyyy") + " already in database");
                }
                else
                {
                    Console.WriteLine("Saving price for " + date.ToString("MM/dd/yyyy") + " - " + price.ToString("c"));
                    DB.AddToCrudeOils(new CrudeOil
                    {
                        Day            = date,
                        price_at_close = price
                    });
                }

                match = match.NextMatch();
            }

            DB.SaveChanges(true);

            Console.WriteLine("Done");
        }