Пример #1
0
        static void MakeRequest(AirlineSearch filters)
        {
            try
            {
                string url = "https://www.kayak.com/flights/AMS-BCN/2018-10-20/2018-10-28?sort=bestflight_a&fs=flexdepart=20181020;flexreturn=20181028";
                url = "https://www.ca.kayak.com/?uuid=89d5d6c0-9bec-11e8-8c5b-df3051146d6e&vid=&url=%2Fflights%2FAMS-BCN%2F2018-10-20%2F2018-10-28%3Fsort%3Dbestflight_a%26fs%3Dflexdepart%3D20181020%3Bflexreturn%3D20181028";
                WebRequest      request  = WebRequest.Create(url);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    Stream       receiveStream = response.GetResponseStream();
                    StreamReader readStream    = null;

                    if (response.CharacterSet == null)
                    {
                        readStream = new StreamReader(receiveStream);
                    }
                    else
                    {
                        readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                    }

                    string data = readStream.ReadToEnd();

                    response.Close();
                    readStream.Close();
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
            }
        }
Пример #2
0
        public static bool SearchFlights(int?SearchTripId, string MainPythonScriptPath, string PythonPath)
        {
            bool result = false;

            try
            {
                AirlineSearch filter1 = new AirlineSearch();
                filter1.FromAirportCode   = "AMS";
                filter1.FromDate          = new DateTime(2018, 10, 20);
                filter1.ToAirportCode     = "BCN";
                filter1.Return            = true;
                filter1.ToDate            = new DateTime(2018, 10, 28);
                filter1.AdultsNumber      = 1;
                filter1.DirectFlightsOnly = true;

                List <ProxyItem> Proxies = ProxyHelper.GetProxies();
                if (Proxies != null && Proxies.Count > 0)
                {
                    // https://raw.githubusercontent.com/clarketm/proxy-list/master/proxy-list.txt
                    string Proxy = ProxyHelper.GetBestProxy(Proxies);
                    if (Proxy == null)
                    {
                        Proxies = ProxyHelper.GetProxies();
                        Proxy   = ProxyHelper.GetBestProxy(Proxies);
                    }

                    ScrappingSearch scrappingSearch = new ScrappingSearch();
                    scrappingSearch.Proxy                = Proxy;
                    scrappingSearch.PythonPath           = PythonPath;
                    scrappingSearch.MainPythonScriptPath = MainPythonScriptPath;
                    scrappingSearch.SearchTripProviderId = 1;
                    scrappingSearch.Provider             = "Edreams";
                    scrappingSearch.ProxiesList          = Proxies;

                    var ScrappingResult = FlighsBot.PythonHelper.SearchViaScrapping(filter1, scrappingSearch);
                    Proxies = ScrappingResult.ProxiesList;

                    result = ScrappingResult.Success;
                }
                //  Task.Factory.StartNew(() => FlighsBot.PythonHelper.Run(filter1, scrappingSearch));
                // Console.WriteLine("Pythonresult = "+ Pythonresult.Success+" and Error = "+ (Pythonresult.Error??""));

                //   FlighsBot.Kayak.SearchFlights(filter1);
                //   FlighsBot.Kayak.SearchFlights(filter1);

                //   FlightsEngine.FlighsAPI.AirFranceKLM.SearchFlights(filter1);
                //    FlightsEngine.FlighsAPI.AirHob.SearchFlights(filter1);
                //   FlightsEngine.FlighsAPI.Kiwi.SearchFlights(filter1);
                // FlightsEngine.FlighsAPI.RyanAir.SearchFlights(filter1);
                //  FlightsEngine.FlighsAPI.Transavia.SearchFlights(filter1);
            }
            catch (Exception e)
            {
                result = false;
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "SearchTripId = " + (SearchTripId == null?"NULL" : SearchTripId.ToString()) + " and MainPythonScriptPath = " + MainPythonScriptPath + " and PythonPath = " + PythonPath);
            }
            return(result);
        }
Пример #3
0
        public static string GetKayakUrl(AirlineSearch filter)
        {
            string url = null;

            try
            {
                url = "https://www.kayak.com/flights/" + filter.FromAirportCode + "-" + filter.ToAirportCode + "/" + filter.FromDate.Value.ToString("yyyy-MM-dd") + "/" + filter.ToDate.Value.ToString("yyyy-MM-dd") + "?sort=bestflight_a";
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Filters = " + filter.ToSpecialString());
            }
            return(url);
        }
Пример #4
0
        public static string GetEdreamsUrl(AirlineSearch filter)
        {
            string url = null;

            try
            {
                url = "https://www.edreams.com/#results/type=R;dep=" + filter.FromDate.Value.ToString("yyyy-MM-dd") + ";from=" + filter.FromAirportCode + ";to=" + filter.ToAirportCode + ";ret=" + filter.ToDate.Value.ToString("yyyy-MM-dd") + ";collectionmethod=false;airlinescodes=false;internalSearch=true";
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Filters = " + filter.ToSpecialString());
            }
            return(url);
        }
Пример #5
0
        public static bool SearchFlights(AirlineSearch filter)
        {
            bool result = false;

            try
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  START Kayak ***");
                MakeRequest(filter);
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Kayak ***");
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filter.ToSpecialString());
            }
            return(result);
        }
Пример #6
0
        public static PythonExecutionResult SearchViaScrapping(AirlineSearch filter, ScrappingSearch scrappingSearch)
        {
            PythonExecutionResult result = new PythonExecutionResult();

            try
            {
                int  nbMaxAttempts   = 3;
                int  nbAttempts      = 0;
                bool continueProcess = true;

                while (continueProcess)
                {
                    nbAttempts = nbAttempts + 1;
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " **  START SearchViaScrapping ** : " + nbAttempts);
                    result = Run(filter, scrappingSearch);

                    ProxyItem proxyItemToModify = scrappingSearch.ProxiesList.Find(p => p.Proxy == scrappingSearch.Proxy);
                    scrappingSearch.ProxiesList.Find(p => p.Proxy == scrappingSearch.Proxy).UseNumber = proxyItemToModify.UseNumber + 1;
                    if (!result.Success)
                    {
                        scrappingSearch.ProxiesList.Find(p => p.Proxy == scrappingSearch.Proxy).Failure = proxyItemToModify.Failure + 1;
                        scrappingSearch.Proxy = ProxyHelper.GetBestProxy(scrappingSearch.ProxiesList);
                    }

                    continueProcess = !result.Success && nbAttempts < nbMaxAttempts;
                }
                result.ProxiesList = scrappingSearch.ProxiesList;
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Error   = e.ToString();
            }
            finally
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " **  END SearchViaScrapping **");
            }

            return(result);
        }
Пример #7
0
        public void ManagerMenu(string FlightOrPassenger)
        {
            string entiti;

            if (FlightOrPassenger == "flight")
            {
                entiti          = "   FLIGHT";
                printList       = x => FlightsManager.PrintList(x);
                printListDouble = printList;
                addToList       = x => FlightsManager.AddToList(x);
                deleteFromList  = x => FlightsManager.DeleteFromList(x);
                editList        = x => FlightsManager.EditList(x);
            }
            else
            {
                entiti           = "PASSENGER";
                printList        = x => FlightsManager.PrintList(x);
                printListDouble  = printList;
                printListDouble += x => PassengerManager.PrintList(x);
                addToList        = x => PassengerManager.AddToList(x);
                deleteFromList   = x => PassengerManager.DeleteFromList(x);
                editList         = x => PassengerManager.EditList(x);
            }
            bool isEnter = true;

            do
            {
                Console.CursorLeft      = 30;
                Console.CursorTop       = 0;
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(@"CONTROL MENU {0}S    |", entiti);
                Console.CursorLeft = 30;
                Console.WriteLine("---------------------------|");
                Console.CursorLeft = 30;
                Console.WriteLine("1 - Print                  |");
                Console.CursorLeft = 30;
                Console.WriteLine("2 - Add                    |");
                Console.CursorLeft = 30;
                Console.WriteLine("3 - Delete                 |");
                Console.CursorLeft = 30;
                Console.WriteLine("4 - Edit                   |");
                Console.CursorLeft = 30;
                Console.WriteLine("5 - Search                 |");
                Console.CursorLeft = 30;
                Console.WriteLine("Any key - Back to MAIN menu|");
                Console.CursorLeft = 30;
                Console.WriteLine("---------------------------|");
                Console.ForegroundColor = ConsoleColor.DarkGray;
                switch (Console.ReadKey().KeyChar)
                {
                case '1':
                    printListDouble(FlightList);
                    Console.WriteLine("Press any key to back menu");
                    Console.ReadKey();
                    CleanerManager.ClearConsole(ClearLineConsole);
                    break;

                case '2':
                    printList(FlightList);
                    if (addToList(FlightList))
                    {
                        Console.WriteLine($"{entiti} successfully added");
                    }
                    else
                    {
                        Console.WriteLine($"{entiti} not added");
                    }
                    Console.WriteLine("Press any key to back menu");
                    Console.ReadKey();
                    CleanerManager.ClearConsole(ClearLineConsole);
                    break;

                case '3':
                    printList(FlightList);
                    if (deleteFromList(FlightList))
                    {
                        Console.WriteLine($"{entiti} successfully deleted");
                    }
                    else
                    {
                        Console.WriteLine($"{entiti} NOT deleted");
                    }
                    Console.WriteLine("Press any key to back menu");
                    Console.ReadKey();
                    CleanerManager.ClearConsole(ClearLineConsole);
                    break;

                case '4':
                    printList(FlightList);
                    if (editList(FlightList))
                    {
                        Console.WriteLine($"{entiti} successfully modified");
                    }
                    else
                    {
                        Console.WriteLine($"{entiti} NOT modified");
                    }
                    Console.WriteLine("Press any key to back menu");
                    Console.ReadKey();
                    CleanerManager.ClearConsole(ClearLineConsole);
                    break;

                case '5':
                    AirlineSearch.SearchMenu(FlightList);
                    CleanerManager.ClearSearchMenu();
                    CleanerManager.ClearConsole(ClearLineConsole);
                    break;

                default:
                    Console.Clear();
                    isEnter = false;
                    break;
                }
            } while (isEnter);
        }
Пример #8
0
        public static PythonExecutionResult Run(AirlineSearch filter, ScrappingSearch scrappingSearch)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  START Scrapping *** : " + (scrappingSearch?.Provider ?? "") + " | " + (scrappingSearch?.Proxy ?? ""));
            PythonExecutionResult result = new PythonExecutionResult();

            System.Diagnostics.Process cmd = new System.Diagnostics.Process();
            try
            {
                // https://stackoverflow.com/questions/1469764/run-command-prompt-commands


                string args = "\"" + scrappingSearch.Proxy + "\" \"" + scrappingSearch.SearchTripProviderId + "\" \"" + scrappingSearch.Provider + "\" \"" + filter.FromAirportCode + "\" \"" + filter.ToAirportCode + "\" \"" + filter.DirectFlightsOnly.ToString().ToLower() + "\" \"" + filter.FromDate.Value.ToString("dd'/'MM'/'yyyy") + "\"";
                if (filter.Return)
                {
                    args = args + " \"" + filter.ToDate.Value.ToString("dd'/'MM'/'yyyy") + "\"";
                }


                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName    = "cmd.exe";
                startInfo.Arguments   = string.Format("/C {0} {1} {2}", scrappingSearch.PythonPath, scrappingSearch.MainPythonScriptPath, args);

                startInfo.RedirectStandardInput  = true;
                startInfo.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow     = false;
                startInfo.UseShellExecute        = false;;

                /*
                 * start.UseShellExecute = false;// Do not use OS shell
                 * start.CreateNoWindow = true; // We don't need new window
                 * start.RedirectStandardOutput = true;// Any output, generated by application will be redirected back
                 * start.RedirectStandardError = true; // Any error in standard output will be redirected back (for example exceptions)
                 */
                cmd.StartInfo = startInfo;
                cmd.Start();
                string        strResult  = "";
                List <string> resultList = new List <string>();
                while (!cmd.StandardOutput.EndOfStream)
                {
                    strResult = cmd.StandardOutput.ReadLine();
                    resultList.Add(strResult);
                }

                if (!String.IsNullOrWhiteSpace(strResult))
                {
                    if (strResult.StartsWith("OK"))
                    {
                        result.Success = true;
                        if (strResult.Contains("|"))
                        {
                            string FoundTripNumber = strResult.Split('|')[1];
                            if (!String.IsNullOrWhiteSpace(FoundTripNumber))
                            {
                                ;
                            }
                            result.FoundTripsNumber = Convert.ToInt32(FoundTripNumber);
                        }
                        result.Error = null;
                    }
                    else
                    {
                        if (strResult.Contains("|"))
                        {
                            result.Error = strResult.Split('|')[1];
                        }
                        if (result.Error == null || result.Error.ToLower() != PythonError.WebdriverTimeout.ToLower())
                        {
                            foreach (string log in resultList)
                            {
                                Console.WriteLine(log);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result.Success = false;
                result.Error   = e.ToString();
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Provider = " + scrappingSearch.Provider + " and Proxy = " + scrappingSearch.Proxy + " and filters = " + filter.ToSpecialString());
            }
            finally
            {
                cmd.StandardInput.WriteLine("exit");
                cmd.WaitForExit();
                cmd.Close();
            }

            if (result.Success)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Scrapping *** : SUCCESS => " + (String.IsNullOrWhiteSpace(result.Error) ? result.FoundTripsNumber.ToString() : result.Error));
            }
            else
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Scrapping *** : FAILURE => " + (result.Error ?? ""));
            }
            return(result);
        }
Пример #9
0
        static bool MakeRequest(AirlineSearch filters)
        {
            bool result = false;

            try
            {
                string url            = "";
                var    httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                httpWebRequest.Headers.Add("Api-Key", Key);


                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    /*
                     * // Request parameters
                     * if (!String.IsNullOrWhiteSpace(filters.AirportDepartureCode))
                     *  queryString["Origin"] = filters.AirportDepartureCode;
                     * if (!String.IsNullOrWhiteSpace(filters.AirportArrivalCode))
                     *  queryString["Destination"] = filters.AirportArrivalCode;
                     * if (filters.DepartureDate != null)
                     *  queryString["OriginDepartureDate"] = filters.DepartureDate.Value.ToString("yyyyMMdd");
                     * if (filters.ArrivalDate != null)
                     *  queryString["OriginArrivalDate"] = filters.ArrivalDate.Value.ToString("yyyyMMdd");
                     * queryString["DirectFlight"] = filters.DirectFlightsOnly.ToString().ToLower();
                     *
                     * if (filters.AdultsNumber != null)
                     *  queryString["Adults"] = filters.AdultsNumber.ToString();
                     * if (filters.ChildrenNumber != null)
                     *  queryString["Children"] = filters.ChildrenNumber.ToString();
                     *
                     *
                     * HubSpotJsonObject jsonObject = new HubSpotJsonObject();
                     * jsonObject.properties.Add(new Property("email", contact.Email));
                     * jsonObject.properties.Add(new Property("firstname", contact.FirstName));
                     * jsonObject.properties.Add(new Property("lastname", contact.LastName));
                     * jsonObject.properties.Add(new Property("website", contact.WebSite));
                     * jsonObject.properties.Add(new Property("company", contact.Company));
                     * jsonObject.properties.Add(new Property("language", contact.Language));
                     * jsonObject.properties.Add(new Property("address", contact.Address));
                     * jsonObject.properties.Add(new Property("city", contact.City));
                     * jsonObject.properties.Add(new Property("state", contact.State));
                     * jsonObject.properties.Add(new Property("zip", contact.Zip));
                     * jsonObject.properties.Add(new Property("gender", contact.Gender));
                     * jsonObject.properties.Add(new Property("birth_date", contact.BirthDate));
                     * jsonObject.properties.Add(new Property("last_connection_date", contact.LastConnectionDate));
                     * jsonObject.properties.Add(new Property("phone", contact.PhoneNumber));
                     * jsonObject.properties.Add(new Property("country", contact.Country));
                     * if (contact.CompletedInvestmentsNumber != null)
                     *  jsonObject.properties.Add(new Property("completed_investments_number", contact.CompletedInvestmentsNumber?.ToString()));
                     * if (contact.CompletedInvestmentsSum != null)
                     *  jsonObject.properties.Add(new Property("completed_investments_sum", contact.CompletedInvestmentsSum?.ToString()));
                     * jsonObject.properties.Add(new Property("hasffaccount", "true"));
                     * jsonObject.properties.Add(new Property("investor_status", contact.InvestorStatus));
                     * jsonObject.properties.Add(new Property("import_data_from_ff_website", contact.Import_data_from_ff_website));
                     * jsonObject.properties.Add(new Property("ff_investor_profile_url", contact.ff_investor_profile_url));
                     * jsonObject.properties.Add(new Property("ff_admin_investor_profile_url", contact.ff_admin_investor_profile_url));
                     * jsonObject.properties.Add(new Property("receive_new_campaign_launches_emails", contact.Receive_new_campaign_launches_emails));
                     * jsonObject.properties.Add(new Property("receive_monthly_news_letter", contact.Receive_monthly_news_letter));
                     * jsonObject.properties.Add(new Property("receive_promotional_emails", contact.Receive_promotional_emails));
                     * jsonObject.properties.Add(new Property("receive_followed_companies_email", contact.receive_followed_companies_email));
                     * jsonObject.properties.Add(new Property("receiveb_blog_emails", contact.Receiveb_blog_emails));
                     * jsonObject.properties.Add(new Property("receive_crypto_updates", contact.Receive_crypto_updates));
                     * jsonObject.properties.Add(new Property("receive_investment_reminders", contact.Receive_investment_reminders));
                     * jsonObject.properties.Add(new Property("has_downloaded_the_funding_guide", contact.Has_downloaded_the_funding_guide));
                     * string json = new JavaScriptSerializer().Serialize(jsonObject);
                     */
                    string json = "ere {\"TripType\": \"O\", \"NoOfAdults\": 1, \"NoOfChilds\": 0, \"NoOfInfants\": 0, \"ClassType\": \"Economy\", \"OriginDestination\": [ { \"Origin\": \"CDG\", \"Destination\": \"BCN\", \"TravelDate\": \"08/08/2018\" } ], \"Currency\": \"USD\" }";
                    streamWriter.Write(json);
                }

                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var requestResult = streamReader.ReadToEnd();

                    if (!String.IsNullOrWhiteSpace(requestResult))
                    {
                        JavaScriptSerializer srRequestResult = new JavaScriptSerializer();
                        dynamic jsondataRequestResult        = srRequestResult.DeserializeObject(requestResult);
                        if (jsondataRequestResult != null && FlightsEngine.Utils.Utils.IsPropertyExist(jsondataRequestResult, ""))
                        {
                            result = true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
            }
            return(result);
        }
Пример #10
0
        static async Task MakeRequest(AirlineSearch filters)
        {
            try
            {
                var client      = new HttpClient();
                var queryString = HttpUtility.ParseQueryString(string.Empty);

                // Request headers
                client.DefaultRequestHeaders.Add("apikey", Key);

                // Request parameters
                if (!String.IsNullOrWhiteSpace(filters.FromAirportCode))
                {
                    queryString["Origin"] = filters.FromAirportCode;
                }
                if (!String.IsNullOrWhiteSpace(filters.ToAirportCode))
                {
                    queryString["Destination"] = filters.ToAirportCode;
                }
                if (filters.FromDate != null)
                {
                    queryString["OriginDepartureDate"] = filters.FromDate.Value.ToString("yyyyMMdd");
                }
                if (filters.ToDate != null)
                {
                    queryString["DestinationDepartureDate"] = filters.ToDate.Value.ToString("yyyyMMdd");
                }
                queryString["DirectFlight"] = filters.DirectFlightsOnly.ToString().ToLower();

                queryString["Adults"]   = filters.AdultsNumber.ToString();
                queryString["Children"] = filters.ChildrenNumber.ToString();

                /*
                 * queryString["DestinationDepartureDate"] = "{string}";
                 * queryString["DestinationArrivalDate"] = "{string}";
                 * queryString["OriginDepartureTime"] = "{string}";
                 * queryString["OriginArrivalTime"] = "{string}";
                 * queryString["DestinationDepartureTime"] = "{string}";
                 * queryString["DestinationArrivalTime"] = "{string}";
                 * queryString["OriginDepartureDayOfWeek"] = "{string}";
                 * queryString["OriginArrivalDayOfWeek"] = "{string}";
                 * queryString["DestinationDepartureDayOfWeek"] = "{string}";
                 * queryString["DestinationArrivalDayOfWeek"] = "{string}";
                 * queryString["DaysAtDestination"] = "{string}";
                 *
                 * queryString["Price"] = "{string}";
                 * queryString["GroupPricing"] = "{string}";
                 * queryString["ProductClass"] = "{string}";
                 * queryString["Offset"] = "{string}";
                 * queryString["Include"] = "{string}";
                 * queryString["OrderBy"] = "{string}";
                 * queryString["LowestPricePerDestination"] = "{string}";
                 * queryString["Loyalty"] = "{string}";
                 * queryString["Limit"] = "{string}";
                 */
                var uri      = "https://api.transavia.com/v1/flightoffers/?" + queryString;
                var response = await client.GetAsync(uri);


                if (response != null)
                {
                    if (response.IsSuccessStatusCode && response.StatusCode.ToString() != "No Content")
                    {
                        var contents = await response.Content.ReadAsStringAsync();

                        JavaScriptSerializer srRequestResult = new JavaScriptSerializer();
                        dynamic jsondataRequestResult        = srRequestResult.DeserializeObject(contents);
                        Console.WriteLine("response: " + response.ToString());
                    }
                    else
                    {
                        FlightsEngine.Utils.Logger.GenerateInfo("Transavia Response unsucessfull :  :" + response.ReasonPhrase + " " + response.RequestMessage + " " + response.StatusCode + " and " + response.ToString() + " and " + filters.ToSpecialString());
                    }
                }
                else
                {
                    FlightsEngine.Utils.Logger.GenerateInfo("Transavia Response null : " + filters.ToSpecialString());
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
            }
        }
Пример #11
0
        static bool MakeRequest(AirlineSearch filters, string TravelHost)
        {
            bool result = false;

            try
            {
                string url            = "https://api.klm.com/opendata/flightoffers/available-offers";
                var    httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method      = "POST";
                httpWebRequest.Headers.Add("Accept-Language", "en-US");
                httpWebRequest.Headers.Add("AFKL-TRAVEL-Host", TravelHost);
                httpWebRequest.Headers.Add("Api-Key", Key);

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    RequestBody body = new RequestBody();
                    body.passengerCount.ADULT  = filters.AdultsNumber;
                    body.passengerCount.CHILD  = filters.ChildrenNumber;
                    body.passengerCount.INFANT = filters.BabiesNumber;


                    connection connection = new connection();
                    connection.departureDate = filters.FromDate.Value.ToString("yyyy-MM-dd");
                    if (!String.IsNullOrWhiteSpace(filters.FromAirportCode))
                    {
                        connection.origin.airport.code = filters.FromAirportCode;
                    }
                    if (!String.IsNullOrWhiteSpace(filters.ToAirportCode))
                    {
                        connection.destination.airport.code = filters.ToAirportCode;
                    }
                    body.requestedConnections.Add(connection);

                    if (filters.DirectFlightsOnly)
                    {
                        body.shortest = true;
                    }

                    if (filters.Return)
                    {
                        connection returnFlight = new connection();
                        returnFlight.departureDate = filters.ToDate.Value.ToString("yyyy-MM-dd");
                        if (!String.IsNullOrWhiteSpace(filters.FromAirportCode))
                        {
                            returnFlight.destination.airport.code = filters.FromAirportCode;
                        }
                        if (!String.IsNullOrWhiteSpace(filters.ToAirportCode))
                        {
                            returnFlight.origin.airport.code = filters.ToAirportCode;
                        }
                        body.requestedConnections.Add(returnFlight);
                    }

                    string json = new JavaScriptSerializer().Serialize(body);
                    streamWriter.Write(json);
                    streamWriter.Flush();
                    streamWriter.Close();
                }

                HttpWebResponse httpResponse = null;
                try
                {
                    result       = true;
                    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                }
                catch (WebException e)
                {
                    result = false;
                    FlightsEngine.Utils.Logger.GenerateWebError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
                }

                if (result)
                {
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var requestResult = streamReader.ReadToEnd();

                        if (!String.IsNullOrWhiteSpace(requestResult))
                        {
                            JavaScriptSerializer srRequestResult = new JavaScriptSerializer();
                            dynamic jsondataRequestResult        = srRequestResult.DeserializeObject(requestResult);
                            if (jsondataRequestResult != null && FlightsEngine.Utils.Utils.IsPropertyExist(jsondataRequestResult, ""))
                            {
                                result = true;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
            }
            return(result);
        }
Пример #12
0
        static async Task MakeRequest(AirlineSearch filters)
        {
            try
            {
                var client      = new HttpClient();
                var queryString = HttpUtility.ParseQueryString(string.Empty);


                // exemple : https://api.skypicker.com/flights?flyFrom=CZ&to=porto&dateFrom=30/08/2018&dateTo=08/09/2018&partner=picky

                // Request parameters
                if (!String.IsNullOrWhiteSpace(filters.FromAirportCode))
                {
                    queryString["flyFrom"] = filters.FromAirportCode;
                }
                if (!String.IsNullOrWhiteSpace(filters.ToAirportCode))
                {
                    queryString["to"] = filters.ToAirportCode;
                }
                if (filters.FromDate != null)
                {
                    queryString["dateFrom"] = filters.FromDate.Value.ToString("dd'/'MM'/'yyyy");
                }
                if (filters.ToDate != null)
                {
                    queryString["dateTo"] = filters.ToDate.Value.ToString("dd'/'MM'/'yyyy");
                }
                queryString["partner"]  = Key;
                queryString["curr"]     = FlightsEngine.Utils.Constants.DefaultCurrency;
                queryString["adults"]   = filters.AdultsNumber.ToString();
                queryString["children"] = filters.ChildrenNumber.ToString();

                /*
                 * queryString["DestinationDepartureDate"] = "{string}";
                 * queryString["DestinationArrivalDate"] = "{string}";
                 * queryString["OriginDepartureTime"] = "{string}";
                 * queryString["OriginArrivalTime"] = "{string}";
                 * queryString["DestinationDepartureTime"] = "{string}";
                 * queryString["DestinationArrivalTime"] = "{string}";
                 * queryString["OriginDepartureDayOfWeek"] = "{string}";
                 * queryString["OriginArrivalDayOfWeek"] = "{string}";
                 * queryString["DestinationDepartureDayOfWeek"] = "{string}";
                 * queryString["DestinationArrivalDayOfWeek"] = "{string}";
                 * queryString["DaysAtDestination"] = "{string}";
                 *
                 * queryString["Price"] = "{string}";
                 * queryString["GroupPricing"] = "{string}";
                 * queryString["ProductClass"] = "{string}";
                 * queryString["Offset"] = "{string}";
                 * queryString["Include"] = "{string}";
                 * queryString["OrderBy"] = "{string}";
                 * queryString["LowestPricePerDestination"] = "{string}";
                 * queryString["Loyalty"] = "{string}";
                 * queryString["Limit"] = "{string}";
                 */
                var uri      = "https://api.skypicker.com/flights?" + queryString;
                var response = await client.GetAsync(uri);


                if (response != null)
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var contents = await response.Content.ReadAsStringAsync();

                        JavaScriptSerializer srRequestResult = new JavaScriptSerializer();
                        dynamic jsondataRequestResult        = srRequestResult.DeserializeObject(contents);
                        Console.WriteLine("response: " + response.ToString());
                    }
                    else
                    {
                        FlightsEngine.Utils.Logger.GenerateInfo("Kiwi Response unsucessfull :  :" + response.ReasonPhrase + " " + response.RequestMessage + " " + response.StatusCode + " and " + response.ToString() + " and " + filters.ToSpecialString());
                    }
                }
                else
                {
                    FlightsEngine.Utils.Logger.GenerateInfo("Kiwi Response null :  " + filters.ToSpecialString());
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filters.ToSpecialString());
            }
        }
Пример #13
0
        public static bool SearchFlights(int?SearchTripWishesId, string ScrappingFolder, string FirefoxExeFolder, int?ProviderId = null)
        {
            bool result = false;

            try
            {
                var context = new TemplateEntities1();
                SearchTripWishesService   _searchTripWishesService   = new SearchTripWishesService(context);
                SearchTripProviderService _searchTripProviderService = new SearchTripProviderService(context);
                TripsService _tripService = new TripsService(context);



                List <ProxyItem> Proxies = null;

                string lastSuccessfullProxy = null;

                List <SearchTripWishesItem> SearchTripWishesItems = _searchTripWishesService.GetSearchTripWishesById(SearchTripWishesId, ProviderId);
                foreach (var SearchTripWishesItem in SearchTripWishesItems)
                {
                    if (SearchTripWishesItem != null && SearchTripWishesItem._SearchTripWishes != null)
                    {
                        var SearchTripWishes = SearchTripWishesItem._SearchTripWishes;

                        #region api

                        APIAirlineSearch APIAirlineSearchItem = new APIAirlineSearch();
                        APIAirlineSearchItem.SearchTripWishesId = SearchTripWishes.Id;
                        if (SearchTripWishes.FromAirport != null)
                        {
                            APIAirlineSearchItem.FromAirportCode = SearchTripWishes.FromAirport.Code;
                        }
                        APIAirlineSearchItem.FromDateMax = SearchTripWishes.FromDateMax;
                        APIAirlineSearchItem.FromDateMin = SearchTripWishes.FromDateMin;
                        if (SearchTripWishes.ToAirport != null)
                        {
                            APIAirlineSearchItem.ToAirportCode = SearchTripWishes.ToAirport.Code;
                        }
                        if (SearchTripWishes.ToDateMin != null)
                        {
                            APIAirlineSearchItem.Return    = true;
                            APIAirlineSearchItem.ToDateMin = SearchTripWishes.ToDateMin;
                            APIAirlineSearchItem.ToDateMax = SearchTripWishes.ToDateMax;
                        }
                        APIAirlineSearchItem.AdultsNumber   = 1;
                        APIAirlineSearchItem.MaxStopsNumber = SearchTripWishes.MaxStopNumber;
                        APIAirlineSearchItem.DurationMin    = SearchTripWishes.DurationMin;
                        APIAirlineSearchItem.DurationMax    = SearchTripWishes.DurationMax;
                        APIAirlineSearchItem.MaxStopsNumber = SearchTripWishes.MaxStopNumber;

                        List <APIKey> AFKLMKeys = FlightsEngine.FlighsAPI.AirFranceKLM.GetAPIKeys();

                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.Kiwi))
                        {
                            Kiwi.SearchFlights(APIAirlineSearchItem);
                        }
                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.AirFrance))
                        {
                            APIKey KeyToUse = AFKLMKeys.Where(k => k.RequestsNumber < 5000).OrderBy(k => k.RequestsNumber).FirstOrDefault();
                            if (KeyToUse != null)
                            {
                                AFKLMKeys.Where(k => k.Key == KeyToUse.Key).FirstOrDefault().RequestsNumber = KeyToUse.RequestsNumber + FlightsEngine.FlighsAPI.AirFranceKLM.SearchFlights(APIAirlineSearchItem, Providers.AirFrance, KeyToUse.Key);
                            }
                        }
                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.KLM))
                        {
                            APIKey KeyToUse = AFKLMKeys.Where(k => k.RequestsNumber < 5000).OrderBy(k => k.RequestsNumber).FirstOrDefault();
                            if (KeyToUse != null)
                            {
                                AFKLMKeys.Where(k => k.Key == KeyToUse.Key).FirstOrDefault().RequestsNumber = KeyToUse.RequestsNumber + FlightsEngine.FlighsAPI.AirFranceKLM.SearchFlights(APIAirlineSearchItem, Providers.KLM, KeyToUse.Key);
                            }
                        }
                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.Transavia))
                        {
                            FlightsEngine.FlighsAPI.Transavia.SearchFlights(APIAirlineSearchItem);
                        }
                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.TurkishAirlines))
                        {
                            FlightsEngine.FlighsAPI.TurkishAirlines.SearchFlights(APIAirlineSearchItem);
                        }
                        if (SearchTripWishesItem.ProvidersToSearch.Select(p => p.Id).Contains(Providers.RyanAir))
                        {
                            FlightsEngine.FlighsAPI.RyanAir.SearchFlights(APIAirlineSearchItem);
                        }
                        #endregion kiwi

                        result = true;
                        bool newProxy = true;
                        foreach (var searchTrip in SearchTripWishes.SearchTrips)
                        {
                            try
                            {
                                AirlineSearch filter = new AirlineSearch();
                                if (SearchTripWishes.FromAirport != null)
                                {
                                    filter.FromAirportCode = SearchTripWishes.FromAirport.Code;
                                }

                                filter.FromDate = searchTrip.FromDate;
                                if (SearchTripWishes.ToAirport != null)
                                {
                                    filter.ToAirportCode = SearchTripWishes.ToAirport.Code;
                                }
                                if (searchTrip.ToDate != null)
                                {
                                    filter.Return = true;
                                    filter.ToDate = searchTrip.ToDate.Value;
                                }
                                filter.AdultsNumber   = 1;
                                filter.MaxStopsNumber = SearchTripWishes.MaxStopNumber;



                                foreach (var provider in SearchTripWishesItem.ProvidersToSearch)
                                {
                                    if (!provider.HasAPI)
                                    {
                                        string Proxy = lastSuccessfullProxy;
                                        if (String.IsNullOrWhiteSpace(Proxy))
                                        {
                                            if (Proxies == null)
                                            {
                                                Proxies = ProxyHelper.GetProxies();
                                            }

                                            Proxy = ProxyHelper.GetBestProxy(Proxies);
                                            if (Proxy == null)
                                            {
                                                Proxies = ProxyHelper.GetProxies();
                                                Proxy   = ProxyHelper.GetBestProxy(Proxies);
                                            }
                                            newProxy = true;
                                        }

                                        ScrappingSearch scrappingSearch = new ScrappingSearch();
                                        if (provider.Id == Providers.Edreams)
                                        {
                                            scrappingSearch.Url = ScrappingHelper.GetEdreamsUrl(filter);
                                        }
                                        else if (provider.Id == Providers.Kayak)
                                        {
                                            scrappingSearch.Url = ScrappingHelper.GetKayakUrl(filter);
                                        }
                                        int SearchTripProviderId = _searchTripProviderService.InsertSearchTripProvider(provider.Id, searchTrip.Id, Proxy, scrappingSearch.Url);
                                        if (!String.IsNullOrWhiteSpace(scrappingSearch.Url) && SearchTripProviderId > 0)
                                        {
                                            scrappingSearch.Proxy            = Proxy;
                                            scrappingSearch.FirefoxExeFolder = FirefoxExeFolder;
                                            scrappingSearch.ScrappingFolder  = ScrappingFolder;
                                            scrappingSearch.NewProxy         = newProxy;
                                            if (SearchTripProviderId > 0 && !String.IsNullOrWhiteSpace(Proxy))
                                            {
                                                filter.SearchTripProviderId = SearchTripProviderId;
                                                scrappingSearch.Provider    = provider.Name;
                                                scrappingSearch.ProxiesList = Proxies;

                                                var ScrappingResult = ScrappingHelper.SearchViaScrapping(scrappingSearch, filter.SearchTripProviderId);
                                                Proxies = ScrappingResult.ProxiesList;
                                                _searchTripProviderService.SetSearchTripProviderAsEnded(SearchTripProviderId, ScrappingResult.Success, ScrappingResult.LastProxy, ScrappingResult.AttemptsNumber);
                                                result = result && ScrappingResult.Success;
                                                if (ScrappingResult.Success)
                                                {
                                                    lastSuccessfullProxy = ScrappingResult.LastProxy;
                                                    _tripService.InsertTrips(SearchTripProviderId);
                                                    newProxy = false;
                                                    //Task.Factory.StartNew(() => { _tripService.InsertTrips(SearchTripProviderId); });
                                                }
                                                else
                                                {
                                                    lastSuccessfullProxy = null;
                                                }
                                            }
                                            else
                                            {
                                                result = false;
                                            }
                                        }
                                        else
                                        {
                                            FlightsEngine.Utils.Logger.GenerateInfo("No url for SearchTripProviderId : " + SearchTripProviderId + " and provider = " + provider.Name);
                                        }
                                    }
                                    else
                                    {
                                        if (provider.Id == Providers.Transavia)
                                        {
                                            //  FlightsEngine.FlighsAPI.Transavia.SearchFlights(filter);
                                        }

                                        int SearchTripProviderId = _searchTripProviderService.InsertSearchTripProvider(provider.Id, searchTrip.Id, null, null);
                                        filter.SearchTripProviderId = SearchTripProviderId;
                                    }
                                }

                                //  Task.Factory.StartNew(() => FlighsBot.PythonHelper.Run(filter, scrappingSearch));
                                // Console.WriteLine("Pythonresult = "+ Pythonresult.Success+" and Error = "+ (Pythonresult.Error??""));

                                //   FlighsBot.Kayak.SearchFlights(filter);
                                //   FlighsBot.Kayak.SearchFlights(filter);

                                //   FlightsEngine.FlighsAPI.AirFranceKLM.SearchFlights(filter);
                                //    FlightsEngine.FlighsAPI.AirHob.SearchFlights(filter);
                                //   FlightsEngine.FlighsAPI.Kiwi.SearchFlights(filter);
                                // FlightsEngine.FlighsAPI.RyanAir.SearchFlights(filter);
                                //  FlightsEngine.FlighsAPI.Transavia.SearchFlights(filter);
                            }
                            catch (Exception e2)
                            {
                                result = false;
                                FlightsEngine.Utils.Logger.GenerateError(e2, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "searchTrip.Id = " + searchTrip.Id);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result = false;
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "SearchTripWishesId = " + (SearchTripWishesId ?? -1) + " and ScrappingFolder = " + ScrappingFolder + " and FirefoxExeFolder = " + FirefoxExeFolder);
            }
            return(result);
        }