Exemplo n.º 1
0
        // Insert flights rows into Scraper
        public void WritePrices()
        {
            FlightsSql       flightsSql   = new FlightsSql(connectionString);
            List <FlightUrl> destinations = flightsSql.LoadDestinationsToScrape(connectionString);

            //Flight object for flight methods
            Flight         flight = new Flight();
            List <decimal> prices = flight.ScrapePrice(DateAndTime.CurrentDateTime(), connectionString);


            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    for (int i = 0; i < prices.Count; i++)
                    {
                        SqlCommand cmd = new SqlCommand(SQL_WriteFlightInfo, conn);

                        cmd.Parameters.AddWithValue("@price", prices[i]);
                        cmd.Parameters.AddWithValue("@originCode", "LAX");
                        cmd.Parameters.AddWithValue("@departureDate", destinations[i].Depart);
                        cmd.Parameters.AddWithValue("@returnDate", destinations[i].Return);
                        cmd.Parameters.AddWithValue("@destinationCode", destinations[i].DestinationAirportCode);
                        cmd.Parameters.AddWithValue("@logTime", DateAndTime.CurrentDateTime());
                        int worked = cmd.ExecuteNonQuery();
                        if (worked > 0)
                        {
                            Console.WriteLine($"Input {worked} row");
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                Email.SendEmailFailure(e.ToString(), "Failed during: public void WritePrices()");
                throw;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string   connectionString = ConfigurationManager.ConnectionStrings["ScraperDatabase"].ConnectionString;
            DateTime start            = DateTime.Now;

            Email.SendEmail("Start Time", $"SurfScraper has started running at: {start.ToString()}");
            Console.WriteLine();
            SurfHeightSql surf = new SurfHeightSql(connectionString);

            //fix wind
            surf.LogSurfData();
            FlightsSql Flights = new FlightsSql(connectionString);

            Flights.WritePrices();

            DateTime end = DateTime.Now;

            Email.SendEmail("End Time", $"SurfScraper has ended running at: {end.ToString()}\n" +
                            $"Total elapsed time: {(end.Subtract(start)).TotalMinutes}");
            Console.WriteLine($"End time: {end.ToString()}");
            Console.WriteLine($"Total elapsed time: {Math.Round((end.Subtract(start)).TotalMinutes, 2)}");
        }