public static AirBnbAccountRooms GetRoomList(IWebDriver driver, AirBnbAccount account, bool isTest = false)
        {
            var accountRooms = new AirBnbAccountRooms
            {
                AccountEmail = account.Email
            };

            NavigateToListing(driver);
            accountRooms.Rooms = ScrapeRooms(driver, account);
            return(accountRooms);
        }
        private static List <AirBnbRoom> ScrapeRooms(IWebDriver driver, AirBnbAccount account)
        {
            var list   = new List <AirBnbRoom>();
            var h4List = driver.FindElements(By.CssSelector("span.h4"));

            foreach (var h4Span in h4List)
            {
                try
                {
                    var a      = h4Span.FindElement(By.TagName("a"));
                    var href   = a.GetAttribute("href");
                    var roomId = href.ExtractNumber();

                    var spans     = h4Span.FindElements(By.TagName("span"));
                    var roomTitle = "";
                    foreach (var span in spans)
                    {
                        try
                        {
                            var text = (span.Text + "").Trim();
                            if (string.IsNullOrWhiteSpace(text))
                            {
                                continue;
                            }

                            roomTitle = text;
                            break;
                        }
                        catch
                        {
                            // ignored
                        }
                    }

                    Console.WriteLine(account.Email + " - " + roomTitle + " - " + roomId);
                    list.Add(new AirBnbRoom
                    {
                        AccountEmail = account.Email,
                        RoomID       = roomId,
                        RoomTitle    = roomTitle
                    });
                }
                catch
                {
                    // ignored
                }
            }

            return(list);
        }
 internal TransactionLoader(AirBnbAccount airAccount, OperationsJsonLogger <LoginAttempt> loginAttemptsProcessor, ILog logger)
 {
     _airAccount             = airAccount;
     _loginAttemptsProcessor = loginAttemptsProcessor;
     _logger = logger;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Push price to airbnb.
        /// </summary>
        /// <param name="processStartTime">Process start time.</param>
        /// <param name="pricePushLogger">Price push logger.</param>
        /// <param name="airBnbProperties">List of airbnb properties.</param>
        public static void PushPriceToAirBnb(DateTime processStartTime, OperationsJsonLogger <PricePushResult> pricePushLogger, List <Property> airBnbProperties)
        {
            List <PricePushResult> pricePushLogResults = new List <PricePushResult>();

            try
            {
                if (airBnbProperties != null)
                {
                    // Group the properties by their login email id.
                    var propertiesGroupedByEmail = airBnbProperties.GroupBy(x => x.LoginAccount.Email);

                    if (propertiesGroupedByEmail != null)
                    {
                        foreach (var propertyGroup in propertiesGroupedByEmail)
                        {
                            // Get the property list that needs to be updated.
                            List <Property> properties = propertyGroup.ToList();

                            // Setup the login acccount which should be used to login to the account.
                            var           loginAccount = properties[0].LoginAccount;
                            AirBnbAccount account      = new AirBnbAccount
                            {
                                Email        = loginAccount.Email,
                                Password     = loginAccount.Password,
                                ProxyAddress = loginAccount.ProxyAddress,
                                Active       = loginAccount.Active,
                                Test         = loginAccount.Test
                            };

                            // Set the firefox profile.
                            //var firefoxProfile = SeleniumProxy.GetFirefoxProfileWithProxy(account.ProxyAddress[0]);
                            var chromeOptions = SeleniumProxy.GetChromeOptionsWithProxy(account.ProxyAddress[0]);
                            try
                            {
                                using (RemoteWebDriver driver = SeleniumFactory.GetChromeDriver(chromeOptions))
                                //using (RemoteWebDriver driver = SeleniumFactory.GetFirefoxDriver(firefoxProfile))
                                {
                                    N.Note("Trying to login with the user :"******"Login succeeded");

                                        foreach (Property property in properties)
                                        {
                                            var validPropertyPrices = property.Prices.Where(x => (x.SeasonEndDate.Date > DateTime.UtcNow.Date));
                                            if (AirBnbCalendar.NavigateToCalendar(driver, property.AirbnbId))
                                            {
                                                ///AirBnbCalendar.ZoomOut(driver);
                                                if (validPropertyPrices.Count() > 0)
                                                {
                                                    string currentMonthYear = string.Empty;
                                                    bool   navigateToMonth  = true;
                                                    foreach (Price propPrice in validPropertyPrices)
                                                    {
                                                        int noOfDays = propPrice.NoOfDaysToBeUpdated();

                                                        if (string.Compare(currentMonthYear, propPrice.SeasonStartDate.Month.ToString() + propPrice.SeasonStartDate.Year.ToString(), true) != 0)
                                                        {
                                                            navigateToMonth = AirBnbCalendar.NavigateToMonth(driver, propPrice.SeasonStartDate.Month, propPrice.SeasonStartDate.Year);

                                                            if (navigateToMonth)
                                                            {
                                                                currentMonthYear = propPrice.SeasonStartDate.Month.ToString() + propPrice.SeasonStartDate.Year.ToString();
                                                            }

                                                            Thread.Sleep(TimeSpan.FromSeconds(2));
                                                        }

                                                        if (navigateToMonth)
                                                        {
                                                            for (int i = 1; i <= noOfDays; i++)
                                                            {
                                                                DateTime startDate = propPrice.SeasonStartDate.AddDays(i);
                                                                if (string.Compare(currentMonthYear, startDate.Month.ToString() + startDate.Year.ToString(), true) != 0)
                                                                {
                                                                    AirBnbCalendar.NavigateToMonth(driver, startDate.Month, startDate.Year);
                                                                    Thread.Sleep(TimeSpan.FromSeconds(2));
                                                                }

                                                                Thread.Sleep(TimeSpan.FromMilliseconds(700));
                                                                N.Note("Updating price for the day :" + propPrice.SeasonStartDate.AddDays(i).ToString("yyyy-MM-dd"));

                                                                try
                                                                {
                                                                    AirBnbCalendar.UpdateUnitPrice(
                                                                        driver,
                                                                        propPrice.SeasonStartDate.AddDays(i),
                                                                        propPrice.PropertyPrice);
                                                                }
                                                                catch (Exception ex)
                                                                {
                                                                    PricingPushLogType logType = PricingPushLogType.Error;
                                                                    if (ex.GetType() == typeof(PriceUpdateInformation))
                                                                    {
                                                                        logType = PricingPushLogType.Information;
                                                                    }

                                                                    LogPriceUpdationError(pricePushLogResults, PricePushLogArea.PriceUpdate, logType, property, propPrice.SeasonStartDate.AddDays(i), propPrice.PropertyPrice, ex.Message);
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            for (int startDay = 1; startDay <= noOfDays; startDay++)
                                                            {
                                                                LogPriceUpdationError(pricePushLogResults, PricePushLogArea.PriceUpdate, PricingPushLogType.Error, property, propPrice.SeasonStartDate.AddDays(startDay), propPrice.PropertyPrice, "Navigating to the month " + propPrice.SeasonStartDate.ToString("MMMM") + " in the calendar failed for the property " + property.AirbnbTitle);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                LogError(pricePushLogResults, PricePushLogArea.Property, PricingPushLogType.Error, property, "Listing Id :" + property.AirbnbId + " for the property " + property.AirbnbTitle + " is wrong");
                                            }

                                            RetryFailedPriceUpdates(driver, pricePushLogResults, property.AirbnbId);
                                        }
                                    }
                                    else
                                    {
                                        LogError(pricePushLogResults, PricePushLogArea.Login, PricingPushLogType.Error, signInSucceed.Message.Replace(System.Environment.NewLine, string.Empty));

                                        try
                                        {
                                            driver.Quit();
                                        }
                                        catch (Exception ex)
                                        {
                                            N.Note("Exception while closing the driver : " + ex.Message);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                LogError(pricePushLogResults, PricePushLogArea.Property, PricingPushLogType.Error, "Pricing push to AirBnb failed", ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(pricePushLogResults, PricePushLogArea.Property, PricingPushLogType.Error, "Pricing push to AirBnb failed", ex.Message);
            }
            finally
            {
                pricePushLogger.Log(pricePushLogResults);
            }
        }
        public static bool DownloadCompletedTransaction(IWebDriver driver, AirBnbAccount account, int Year)
        {
            driver.GoTo(url);
            var _wait = new WebDriverWait(driver, new TimeSpan(0, 0, Config.I.RegularWaitSeconds * 2));

            // ждем пока загрузится
            _wait.Until(ExpectedConditions.ElementExists(By.CssSelector(".transaction-table")));

            driver.JustWait(1);

            try
            {
                //class="payout-method" => value=""
                var payoutMethod = new SelectElement(driver.FindElement(By.CssSelector(".payout-method")));
                payoutMethod.SelectByValue("");
            }
            catch
            {
            }


            try
            {
                //class="payout-listing" => value=""
                var payoutListing = new SelectElement(driver.FindElement(By.CssSelector(".payout-listing")));
                payoutListing.SelectByValue("");
            }
            catch
            {
            }


            try
            {
                //class="payout-year" => current year
                var payoutYear = new SelectElement(driver.FindElement(By.CssSelector(".payout-year")));
                payoutYear.SelectByValue(Year.ToString());
            }
            catch
            {
            }


            //class="payout-start-month" => 1
            var payoutStartMonth = new SelectElement(driver.FindElement(By.CssSelector(".payout-start-month")));

            payoutStartMonth.SelectByValue("1");


            try
            {
                //class="payout-end-month" => 12
                var payoutEndMonth = new SelectElement(driver.FindElement(By.CssSelector(".payout-end-month")));
                payoutEndMonth.SelectByValue("12");
            }
            catch
            {
            }

            try
            {
                //class="export-csv-link" => click to download
                var AExportCsvLink = driver.FindElement(By.CssSelector("a.export-csv-link"));
                AExportCsvLink.Click();
                driver.JustWait(10);
            }
            catch
            {
                return(false);
            }

            return(true);
            //
        }
Ejemplo n.º 6
0
        public static LoginResult Process(IWebDriver driver, AirBnbAccount Account)
        {
            var loginResult = new LoginResult();

            try
            {
                try
                {
                    driver.GoTo("https://www.airbnb.com/login");

                    var emailInput    = driver.FindElement(By.Id("signin_email"));
                    var passwordInput = driver.FindElement(By.Id("signin_password"));
                    var submit        = driver.FindElement(By.Id("user-login-btn"));

                    emailInput.SendKeys(Account.Email);
                    passwordInput.SendKeys(Account.Password);
                    passwordInput.Submit();
                }
                catch
                {
                    try
                    {
                        var errorElement = driver.FindElement(By.Id("errorTitleText"));

                        if (string.Compare(errorElement.Text, ProxyErrorMessage, true) == 0)
                        {
                            loginResult.Status  = AirBnbLoginStatus.ProxyError;
                            loginResult.Message = ProxyErrorMessage;
                            return(loginResult);
                        }
                        else if (string.Compare(errorElement.Text, TimedOutErrorMessage, true) == 0)
                        {
                            loginResult.Status  = AirBnbLoginStatus.TimedOut;
                            loginResult.Message = TimedOutErrorMessage;
                            return(loginResult);
                        }
                    }
                    catch (Exception)
                    {
                        loginResult.Status = AirBnbLoginStatus.PageError;
                        return(loginResult);
                    }
                }

                driver.JustWait(1);

                try
                {
                    var alert = driver.FindElement(By.CssSelector(".alert.alert-notice.alert-info")).Text;
                    if (!string.IsNullOrEmpty(alert))
                    {
                        loginResult.Status  = AirBnbLoginStatus.Failed;
                        loginResult.Message = alert;
                        return(loginResult);
                    }
                }
                catch
                {
                    // ignored
                }

                try
                {
                    var a = driver.FindElement(By.XPath("//*[contains(text(), 'Unable to perform')]"));
                    if (a != null)
                    {
                        loginResult.Status = AirBnbLoginStatus.Unable;
                        return(loginResult);
                    }
                }
                catch
                {
                    // ignored
                }

                driver.JustWait(5);

                if (driver.Url.Contains(@"airbnb.com/dashboard"))
                {
                    loginResult.Status = AirBnbLoginStatus.Sucess;
                    return(loginResult);
                }

                if (driver.Url.Contains(@"airbnb.com/airlock"))
                {
                    loginResult.Status = AirBnbLoginStatus.VerifyUser;
                    return(loginResult);
                }

                if (driver.Url.Contains(@"airbnb.com/remember_browser"))
                {
                    try
                    {
                        var siteContent = driver.FindElement(By.Id("site-content"));
                        var button      = siteContent.FindElement(By.TagName("button"));
                        button.Click();
                        driver.JustWait(2);
                    }
                    catch (Exception)
                    {
                        loginResult.Status = AirBnbLoginStatus.VerifyBrowser;
                        return(loginResult);
                    }
                }

                loginResult.Status = AirBnbLoginStatus.Sucess;
            }
            catch (Exception)
            {
                if (driver == null)
                {
                    loginResult.Status = AirBnbLoginStatus.Failed;
                    return(loginResult);
                }

                // As per the existing program this code will never be hit, Hence commenting the same out. Since the same is used by different projects.

                //try
                //{
                //    var errorElement = driver.FindElement(By.Id("errorTitleText"));
                //    if (errorElement.Text == "The proxy server is refusing connections")
                //    {
                //        loginResult.Status = AirBnbLoginStatus.ProxyError;
                //        loginResult.Message = "The proxy server is refusing connections";
                //        return loginResult;
                //    }
                //}
                //catch (Exception)
                //{
                //    loginResult.Status = AirBnbLoginStatus.Failed;
                //    return loginResult;
                //}
            }

            return(loginResult);
        }
 public static ReservationInfo GetFullReservationInfo(ReservationInfo Item, RemoteWebDriver Driver, AirBnbAccount Account, bool IsTest = false)
 {
     return(GetReservationInfo(Driver, Item, IsTest));
 }
        /*
         * public static ReservationInfo Process(RemoteWebDriver Driver, AirBnbAccount Account, bool IsTest = false)
         * {
         *  ReservationInfo info = GetReservationInfo(Driver, items[0], IsTest);
         *  return info;
         * }
         * //*/

        public static List <ReservationInfo> ScrapeReservationList(RemoteWebDriver Driver, AirBnbAccount Account, bool IsTest = false)
        {
            var items = GetAllReservationItems(Driver, IsTest);

            return(items);
        }