Esempio n. 1
0
 def click_page_down(self, driver):
     for i in range(0, appconfig.get_number_of_scroll_page()):
         body = driver.find_element_by_css_selector('body')
         body.send_keys(Keys.PAGE_DOWN)
         common_lib.wait(common_lib.__SHORTEST_TIME__,
                         "Page Down - Thread %d" % self.thread_id)
     common_lib.wait(common_lib.__MIDDLE_TIME__,
                     "Page Down - Thread %d" % self.thread_id)
Esempio n. 2
0
 def click_like_page(self, driver):
     try:
         self.driver.find_element_by_xpath(
             '//div[@id="substream_1"]//*[contains(text(),"Like Page")]'
         ).click()
     except Exception as e:
         print e
     common_lib.wait(common_lib.__MIDDLE_TIME__,
                     "Like Page - Thread %d" % self.thread_id)
Esempio n. 3
0
    def __callback(self):
        # login time
        _login_time = time()
        try:
            __login_error__ = False
            try:
                self.driver = self.init_chrome_driver(self.thread_id)
                self.init_chrome_extension(self.driver)
            except Exception as e:
                print e
                __login_error__ = True
                return
            # log on facebook
            try:
                self.log_in_facebook(self.driver)
            except Exception as e:
                print e
                __login_error__ = True
                return
            # click not now button or homepage button
            try:
                self.click_not_now(self.driver)
            except Exception as e:
                print e
                self.click_homepage(self.driver)
            next_time = appconfig.get_next_click_time()
            while (True):
                if appconfig.is_night_time(self.night_time) == True:
                    break
                count_scroll = appconfig.get_number_of_scroll_page()
                if time() > next_time:
                    self.click_like_page(self.driver)
                    next_time = appconfig.get_next_click_time()

                while (count_scroll > 0):
                    count_scroll = count_scroll - 1
                    self.click_page_down(self.driver)
                    if appconfig.get_random_select():
                        count_scroll = count_scroll - 1
                        self.scroll_page(self.driver, False)

                common_lib.wait(common_lib.__LONGEST_TIME__,
                                "REST - Thread %d" % self.thread_id)
                self.click_homepage(self.driver)

        except Exception as e:
            print e
        finally:
            print "Thread", self.thread_id, ":Stop", ", Running Hour(miniute):", self.get_time_from_login(
                _login_time) / 60
            common_lib.wait(common_lib.__MIDDLE_TIME__,
                            "Exit - Thread %d" % self.thread_id)
            if __login_error__ == False:
                self.driver.close()
                self.driver.quit()
Esempio n. 4
0
 def click_homepage(self, driver):
     try:
         WebDriverWait(self.driver, 10).until(
             EC.presence_of_element_located(
                 (By.XPATH, '//*[contains(text(), "Home")]')))
         driver.find_element_by_xpath(
             '//*[contains(text(), "Home")]').click()
     except Exception as e:
         print e
         driver.find_element_by_xpath(
             '//*[contains(text(),"Facebook")]').click()
     common_lib.wait(common_lib.__MIDDLE_TIME__, "")
Esempio n. 5
0
 def scroll_page(self, driver, isdown):
     windowsHeight = int(
         float(driver.execute_script('return window.innerHeight')) *
         appconfig.get_height_ratio())
     if isdown:
         for i in range(0, windowsHeight, 50):
             scrollTop = int(
                 driver.execute_script('return document.body.scrollTop'))
             scrollHeight = int(
                 driver.execute_script('return document.body.scrollHeight'))
             top = min(scrollTop + 50, scrollHeight)
             driver.execute_script('window.scrollTo(0,' + str(top) + ')')
             if i % 400 == 0:
                 common_lib.wait(common_lib.__SHORT_TIME__,
                                 "Scroll Down - Thread %d" % self.thread_id)
             else:
                 common_lib.wait(common_lib.__SHORTEST_TIME__,
                                 "Scroll Down - Thread %d" % self.thread_id)
     else:
         for i in range(0, windowsHeight, 100):
             scrollTop = int(
                 driver.execute_script('return document.body.scrollTop'))
             scrollHeight = int(
                 driver.execute_script('return document.body.scrollHeight'))
             top = max(scrollTop - 100, 0)
             if top == 0: break
             driver.execute_script('window.scrollTo(0,' + str(top) + ')')
             if i % 600 == 0:
                 common_lib.wait(common_lib.__SHORT_TIME__,
                                 "Scroll UP - Thread %d" % self.thread_id)
             else:
                 common_lib.wait(common_lib.__SHORTEST_TIME__,
                                 "Scroll UP - Thread %d" % self.thread_id)
Esempio n. 6
0
 def log_in_facebook(self, driver):
     driver.get(appconfig.__APP_URL__)
     common_lib.wait(common_lib.__SHORT_TIME__, "BEFORE LOGIN")
     username = agents.accounts[self.thread_id].split(':')[0]
     password = agents.accounts[self.thread_id].split(':')[1]
     print username, password
     driver.find_element_by_id('email').send_keys(username)
     common_lib.wait(common_lib.__SHORT_TIME__, "INPUT EMAIL")
     driver.find_element_by_id('pass').send_keys(password)
     common_lib.wait(common_lib.__SHORT_TIME__, "INPUT PASSWORD")
     driver.find_element_by_xpath(
         '//input[@data-testid="royal_login_button"]').click()
     common_lib.wait(common_lib.__MIDDLE_TIME__, "CLICK LOGIN BUTTON")
Esempio n. 7
0
 def init_chrome_extension(self, driver):
     driver.get(appconfig.__OPTION_PATH__)
     common_lib.wait(common_lib.__SHORTEST_TIME__, "EXTENSION START")
     driver.find_element_by_id('inputUserId').send_keys(
         appconfig.__USER_ID_FOR_EXT__)
     common_lib.wait(common_lib.__SHORT_TIME__,
                     "INPUT USER ID ON EXTENSION")
     driver.find_element_by_id('save').click()
     self.accept_alert(driver)
     common_lib.wait(common_lib.__SHORT_TIME__, "EXTENSION END")
Esempio n. 8
0
 def click_not_now(self, driver):
     driver.find_element_by_xpath('//*[contains(text(),"Not Now")]').click()
     common_lib.wait(common_lib.__MIDDLE_TIME__, "Click Not Now")