Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        public static bool SearchFlights(AirlineSearch filter)
        {
            bool result = false;

            try
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  START Ryan Air  ***");
                MakeRequest(filter);

                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Ryan Air  ***");
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, filter.ToSpecialString());
            }
            return(result);
        }
Example #6
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());
            }
        }
Example #7
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());
            }
        }
Example #8
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);
        }
Example #9
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());
            }
        }