Example #1
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);
        }
Example #2
0
        public static ScrappingExecutionResult SearchViaScrapping(ScrappingSearch scrappingSearch, int SearchTripProviderId)
        {
            ScrappingExecutionResult result = new ScrappingExecutionResult();

            try
            {
                int  nbMaxAttempts   = 50;
                bool continueProcess = true;
                int  attemtNumber    = 0;

                while (continueProcess)
                {
                    attemtNumber = attemtNumber + 1;
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " **  START SearchViaScrapping ** : " + attemtNumber);
                    result = Run(scrappingSearch, SearchTripProviderId);
                    if (scrappingSearch.ProxiesList == null || scrappingSearch.ProxiesList.Count == 0 || (!result.Success && (attemtNumber == 10 || attemtNumber == 20 || attemtNumber == 30)))
                    {
                        scrappingSearch.ProxiesList = ProxyHelper.GetProxies();
                    }
                    else
                    {
                        ProxyItem proxyItemToModify = scrappingSearch.ProxiesList.Find(p => p.Proxy == scrappingSearch.Proxy);
                        if (proxyItemToModify != null)
                        {
                            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;
                            }
                        }
                    }
                    if (!result.Success)
                    {
                        scrappingSearch.Proxy    = ProxyHelper.GetBestProxy(scrappingSearch.ProxiesList);
                        scrappingSearch.NewProxy = true;
                    }

                    continueProcess = !result.Success && attemtNumber < nbMaxAttempts;
                }
                result.LastProxy      = scrappingSearch.Proxy;
                result.AttemptsNumber = attemtNumber;
                result.ProxiesList    = scrappingSearch.ProxiesList;
            }
            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 url = " + scrappingSearch.Url);
            }
            finally
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " **  END SearchViaScrapping **");
            }

            return(result);
        }
Example #3
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);
        }
Example #4
0
        public static ScrappingExecutionResult Run(ScrappingSearch scrappingSearch, int SearchTripProviderId)
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  START Scrapping *** : " + (scrappingSearch?.Provider ?? "") + " | " + (scrappingSearch?.Proxy ?? ""));
            ScrappingExecutionResult result = new ScrappingExecutionResult();
            bool success = false;

            System.Diagnostics.Process cmd = new System.Diagnostics.Process();
            try
            {
                #region preparation and purge
                //1) PREPARATION
                // model =>   D:\DEV\FlightEngine\Batch\WebScraperBash\PrepareScrapping.cmd "D:\DEV\FlightEngine\Batch\WebScraperBash" "126" "83.166.99.11" 54457
                string args = "\"" + scrappingSearch.ScrappingFolder + "\" \"" + SearchTripProviderId + "\"";

                if (!scrappingSearch.NewProxy || String.IsNullOrWhiteSpace(scrappingSearch.Proxy))
                {
                    args = args + " \"\" -1";
                }
                else
                {
                    args = args + " \"" + scrappingSearch.Proxy.Split(':')[0] + "\" " + scrappingSearch.Proxy.Split(':')[1].Split(' ')[0];
                }

                //   string args = "\"" + scrappingSearch.ScrappingFolder + "\" \"" + scrappingSearch.SearchTripProviderId + "\" \"\" \"\" ";
                System.Diagnostics.ProcessStartInfo startInfoPreparation = new System.Diagnostics.ProcessStartInfo();
                startInfoPreparation.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfoPreparation.FileName               = "cmd.exe";
                startInfoPreparation.Arguments              = string.Format("/C {0} {1}", scrappingSearch.ScrappingPreparationScript, args);
                startInfoPreparation.RedirectStandardInput  = true;
                startInfoPreparation.RedirectStandardOutput = true;
                cmd.StartInfo.CreateNoWindow         = false;
                startInfoPreparation.UseShellExecute = false;;

                cmd.StartInfo = startInfoPreparation;
                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"))
                    {
                        success      = true;
                        result.Error = null;
                    }
                }
                #endregion

                #region Scrapping
                // Check if preparation is OK
                if (success)
                {
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Preparation / Call AutoHotKey ***");
                    // 2 SCRAPPING
                    // "D:\DEV\FlightEngine\Batch\WebScraperBash\Scrapper.exe" "https://www.edreams.com/#results/type=R;dep=2018-10-22;from=YVR;to=LON;ret=2018-11-19;collectionmethod=false;airlinescodes=false;internalSearch=true" "126" "C:\Users\franc\AppData\Local\Mozilla Firefox\firefox.exe" "eDreams"
                    //  string url = "https://www.edreams.com/#results/type=R;dep=2018-10-22;from=YVR;to=LON;ret=2018-11-19;collectionmethod=false;airlinescodes=false;internalSearch=true";
                    args = "\"" + scrappingSearch.Url + "\" \"" + SearchTripProviderId + "\" \"" + scrappingSearch.FirefoxExeFolder + "\"  \"" + scrappingSearch.Provider + "\"";
                    //  args= ""C:\DEV\FlightEngine\Batch\WebScraperBash\Scrapper.exe" "https://www.edreams.com/#results/type=R;dep=2018-10-22;from=YVR;to=LON;ret=2018-11-19;collectionmethod=false;airlinescodes=false;internalSearch=true" "16" "C:\Program Files\Mozilla Firefox\firefox.exe" "Edreams""
                    System.Diagnostics.ProcessStartInfo startInfoScrapping = new System.Diagnostics.ProcessStartInfo();
                    startInfoScrapping.WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden;
                    startInfoScrapping.FileName               = "cmd.exe";
                    startInfoScrapping.Arguments              = string.Format("/C {0} {1}", scrappingSearch.ScrappingExeScript, args);
                    startInfoScrapping.RedirectStandardInput  = true;
                    startInfoScrapping.RedirectStandardOutput = true;
                    cmd.StartInfo.CreateNoWindow              = false;
                    startInfoScrapping.UseShellExecute        = false;;

                    cmd.StartInfo = startInfoScrapping;
                    cmd.Start();
                    strResult  = "";
                    resultList = new List <string>();
                    while (!cmd.StandardOutput.EndOfStream)
                    {
                        strResult = cmd.StandardOutput.ReadLine();
                        resultList.Add(strResult);
                    }

                    int i = 0;

                    string HtmlFile       = "D:\\Html\\search_" + SearchTripProviderId + ".html";
                    string HtmlErrorFile  = "D:\\Html\\search_" + SearchTripProviderId + ".xht";
                    string StopSearchFile = "D:\\Html\\stopsearch_" + SearchTripProviderId + ".txt";
                    success = false;
                    while (!File.Exists(HtmlFile) && !File.Exists(HtmlErrorFile) && !File.Exists(StopSearchFile) && i <= 20) //limit the time to whait to 30 sec
                    {
                        Thread.Sleep(500);
                        i++;
                    }
                    if (File.Exists(HtmlFile))
                    {
                        if (scrappingSearch.Provider == Providers.ToString(Providers.Kayak))
                        {
                            success = IsKayakSuccessfullSearch(HtmlFile);
                        }
                        else
                        {
                            success = true;
                        }
                        if (!success)
                        {
                            Task.Factory.StartNew(() => { Thread.Sleep(500); File.Delete(HtmlFile); });
                        }
                    }
                }
                #endregion
            }
            catch (Exception e)
            {
                success      = false;
                result.Error = e.ToString();
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Provider = " + scrappingSearch.Provider + " and Proxy = " + scrappingSearch.Proxy + " and url = " + scrappingSearch.Url);
            }
            finally
            {
                cmd.StandardInput.WriteLine("exit");
                cmd.WaitForExit();
                cmd.Close();
                result.Success = success;
            }

            if (success)
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Scrapping *** : SUCCESS  ");
            }
            else
            {
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ***  END Scrapping *** : FAILURE => " + (result.Error ?? ""));
            }
            return(result);
        }
Example #5
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 #6
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);
        }