Esempio n. 1
0
        public static List <Airports> GetAirportsFromList()
        {
            List <Settings> settings = SettingsHelper.GetSettings();
            var             airports = settings.Where(x => x.Key == "Airports").FirstOrDefault().Value;

            List <Airports> listAirportSelected = new List <Airports>();

            foreach (string air in airports.Split(','))
            {
                using (var context = new FodEntities())
                {
                    var a = context.Airports.Where(x => x.Id.ToLower() == air.ToLower()).FirstOrDefault();
                    if (a != null)
                    {
                        listAirportSelected.Add(a);
                    }
                }
            }
            return(listAirportSelected);
        }
Esempio n. 2
0
        public static void ComponiRicercaTransavia()
        {
            var       searchFroms = "http://www.transavia.com/hv/it-IT/home";
            WebClient client      = new WebClient();
            string    html        = client.DownloadString(searchFroms);
            //Parse aereoporti
            var froms = html.Remove(0, html.IndexOf("<div id=\"ffrom\">"));

            froms = froms.Remove(froms.IndexOf("</select></div>"));
            froms = froms.Remove(0, froms.IndexOf("<option value=\"ZZZ\"/>")).Replace("<option value=\"ZZZ\"/>", "").Replace("</option>", "§");
            var airports = froms.Split('§');

            var             fromItalianAirports = new List <Airports>();
            var             toAirports          = new List <Airports>();
            List <Airports> listAirportSelected = FOD.Helpers.AirportHelper.GetAirportsFromList();

            foreach (var a in airports)
            {
                if (a.Length >= 15)
                {
                    var air = a.Substring(15, 3);
                    if (listAirportSelected.Any(x => x.Id == air))
                    {
                        fromItalianAirports.Add(new Airports {
                            Id = air
                        });
                    }
                    else
                    {
                        toAirports.Add(new Airports {
                            Id = air
                        });
                    }
                }
            }



            var searchPattern = "http://www.transavia.com/hv/main/nav/processflightqry?toDay={1}&toMonth={3}&lang=it&adults=1&from={4}&fromMonth={2}&to={5}&country=IT&infants=0&children=0&fromDay={0}&opensearchform=true&tab=cal";
            List <RicercheVoli> ParametriRicerca = new List <RicercheVoli>();
            List <Settings>     settings         = SettingsHelper.GetSettings();
            string price     = settings.Where(x => x.Key == "Price").FirstOrDefault().Value.ToString();
            int    dateRange = Convert.ToInt32(settings.Where(x => x.Key == "DateRange").FirstOrDefault().Value.ToString());
            int    minTrip   = Convert.ToInt32(settings.Where(x => x.Key == "MinTrip").FirstOrDefault().Value.ToString());
            int    maxTrip   = Convert.ToInt32(settings.Where(x => x.Key == "MaxTrip").FirstOrDefault().Value.ToString());
            string dateMin   = settings.Where(x => x.Key == "DateMin").FirstOrDefault().Value.ToString();

            foreach (var air in fromItalianAirports)
            {
                DateTime dateOut = string.IsNullOrEmpty(dateMin) ? DateTime.Now : Convert.ToDateTime(dateMin);
                DateTime dateOutCalculed;
                DateTime dateInCalculed;
                DateTime dateIn        = dateOut;
                string   DateInString  = string.Empty;
                string   DateOutString = string.Empty;

                dateIn = dateOut.AddDays(dateRange);
                int months = dateRange / 30 + 1;

                foreach (var toDestination in toAirports)
                {
                    bool noroute = false;
                    for (int i = 0; i < months; i++)
                    {
                        if (!noroute)
                        {
                            dateOutCalculed = dateOut.AddDays(30 * i);

                            dateInCalculed = dateOutCalculed.AddDays(30 * i);
                            DateOutString  = dateOutCalculed.ToString("yyyy-MM");
                            DateInString   = dateInCalculed.ToString("yyyy-MM");

                            string result = string.Empty;
                            bool   error  = false;
                            string url    = string.Format(searchPattern, dateOut.Day.ToString(), dateIn.Day.ToString(), DateOutString, DateInString, air.Id, toDestination.Id);
                            try
                            {
                                result = client.DownloadString(url);
                            }
                            catch (Exception ex)
                            {
                                noroute = true;
                                error   = true;
                            }
                            if (!result.Contains("Durante la sua prenotazione si è verificato un errore.") && !error)
                            {
                                ParametriRicerca.Add(new RicercheVoli {
                                    Url = url, FromCode = air.Id, Vettore = "Transavia"
                                });
                            }
                        }
                    }
                }
            }

            using (var context = new FodEntities())
            {
                foreach (var p in ParametriRicerca)
                {
                    if (!context.RicercheVolis.Any(x => x.Url == p.Url))
                    {
                        //Verifica Link



                        context.RicercheVolis.AddObject(new RicercheVoli
                        {
                            Url         = p.Url,
                            Processato  = false,
                            DataRicerca = DateTime.Now,
                            FromCode    = p.FromCode,
                            Vettore     = p.Vettore
                        });
                    }
                }
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void ComponiRicerca()
        {
            string searchPattern = "http://www.ryanair.com/it/voli-economici/?price={0}&limit=150&offset=0&from={1}&to=&out-date-start={2}&out-date-end={3}&in-date-start={4}&in-date-end={5}&roundtrip=1&min-trip={6}&max-trip={7}&view=list";
            List <RicercheVoli> ParametriRicerca = new List <RicercheVoli>();
            List <Settings>     settings         = SettingsHelper.GetSettings();
            string price     = settings.Where(x => x.Key == "Price").FirstOrDefault().Value.ToString();
            int    dateRange = Convert.ToInt32(settings.Where(x => x.Key == "DateRange").FirstOrDefault().Value.ToString());
            int    minTrip   = Convert.ToInt32(settings.Where(x => x.Key == "MinTrip").FirstOrDefault().Value.ToString());
            int    maxTrip   = Convert.ToInt32(settings.Where(x => x.Key == "MaxTrip").FirstOrDefault().Value.ToString());
            string dateMin   = settings.Where(x => x.Key == "DateMin").FirstOrDefault().Value.ToString();

            List <Airports> listAirportSelected = FOD.Helpers.AirportHelper.GetAirportsFromList();


            DateTime dateOut       = string.IsNullOrEmpty(dateMin) ? DateTime.Now : Convert.ToDateTime(dateMin);
            TimeSpan ts            = new TimeSpan(dateRange, 0, 0, 0);
            DateTime dateIn        = dateOut.Add(ts);
            string   DateOutString = dateOut.ToString("yyyy-MM-dd");
            string   DateInString  = dateIn.ToString("yyyy-MM-dd");

            foreach (var air in listAirportSelected)
            {
                //DateTime dateOut = string.IsNullOrEmpty(dateMin) ? DateTime.Now : Convert.ToDateTime(dateMin);
                //DateTime dateOutCalculed;
                //DateTime dateInCalculed;
                //DateTime dateIn = dateOut;
                //string DateInString = string.Empty;
                //string DateOutString = string.Empty;
                ////for (int i = 0; i < dateRange; i++)
                ////{

                //dateOutCalculed = dateOut.AddDays(dateRange);
                for (int j = minTrip; j < maxTrip; j++)
                {
                    //dateInCalculed = dateOutCalculed.AddDays(j);
                    //DateOutString = dateOutCalculed.ToString("yyyy-MM-dd");
                    //DateInString = dateInCalculed.ToString("yyyy-MM-dd");
                    string url = string.Format(searchPattern, price, air.Id, DateOutString, DateInString, DateOutString, DateInString, j.ToString(), j.ToString());
                    ParametriRicerca.Add(new RicercheVoli {
                        Url = url, FromCode = air.Id, Vettore = "Ryanair"
                    });
                }

                //}
            }


            using (var context = new FodEntities())
            {
                foreach (var p in ParametriRicerca)
                {
                    if (!context.RicercheVolis.Any(x => x.Url == p.Url))
                    {
                        context.RicercheVolis.AddObject(new RicercheVoli
                        {
                            Url         = p.Url,
                            Processato  = false,
                            DataRicerca = DateTime.Now,
                            FromCode    = p.FromCode,
                            Vettore     = p.Vettore
                        });
                    }
                    context.SaveChanges();
                }
            }
        }