Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from time import localtime, strftime
- from time import sleep
- import sys
- from selenium import webdriver
- from selenium.common.exceptions import StaleElementReferenceException
- # from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.common.action_chains import ActionChains
- opts = Options()
- opts.add_argument(
- "user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36")
- class WorkChecker:
- def __init__(self, action, user, passw):
- # self.display = Display(visible=0, size=(1920, 1080))
- # self.display.start()
- self.action = action
- self.user = user
- self.passw = passw
- self.driver = webdriver.Chrome()
- def __del__(self):
- pass
- # self.display.stop()
- self.driver.close()
- def start(self):
- self.driver.get('https://rm.wildberries.ru/#/layout/employee/work-time')
- if self.action == 1:
- print("Доброе утро! Пытаюсь выполнить вход для {}".format(self.user))
- if self.action == 2:
- print("Пора домой. Пытаюсь выполнить выход для {}".format(self.user))
- print('Загружаю страницу логина/пароля 6 секунд ...')
- sleep(12)
- user = self.refresh_idfind('globalModalLoginFormUsername')
- passw = self.refresh_idfind('globalModalLoginFormPassword')
- button = self.refresh_idfind('globalModalLoginFormLoginButton')
- assert "Торговая точка" in self.driver.title
- user.send_keys(self.user)
- passw.send_keys(self.passw)
- self.click_simple(button)
- print('Перехожу на ввод шк')
- sleep(10)
- sk = self.refresh_xfind(
- '//*[@id="main"]/ng-outlet/select-office/page/section/main/page-section/section/main/form/page-section-row/div/div[1]/input')[
- 0]
- sk.send_keys('OFFC0000100746')
- print('Перехожу на страницу отметок')
- sleep(10)
- bt_exit = self.refresh_xfind(
- '//*[@id="main"]/ng-outlet/work-time-registration-component/page/section/main/page-section/section/main/page-section-row[3]/div/div/input[2]')[
- 0]
- bt_enter = self.refresh_xfind(
- '//*[@id="main"]/ng-outlet/work-time-registration-component/page/section/main/page-section/section/main/page-section-row[3]/div/div/input[1]')[
- 0]
- if self.action == 1:
- self.click_simple(bt_enter)
- sleep(1)
- data = self.refresh_xfind('//*[@id="main"]/ng-outlet/work-time-registration-component\
- /page/section/main/page-section/section/main/page-section-row[2]/div/div/div[2]/div/label/b')[0].text
- if not self.check_data(data):
- print('ОШИБКА! Дата не обновилась!')
- return
- if self.action == 2:
- self.click_simple(bt_exit)
- sleep(1)
- data = self.refresh_xfind('//*[@id="main"]/ng-outlet/work-time-registration-component\
- /page/section/main/page-section/section/main/page-section-row[2]/div/div/div[3]/div/label/b')[0].text
- if not self.check_data(data):
- print('ОШИБКА! Дата не обновилась!')
- return
- print('Время обновления {}'.format(data))
- print('Готово!')
- def check_data(self, data):
- '''
- check day
- :param data: str like 06.10.2017 9:47:56
- :return: true if today
- '''
- return data[:10] == strftime("%d.%m.20%y", localtime())
- def click_and_hold(self, element):
- ActionChains(self.driver).click_and_hold(element).perform()
- def click_simple(self, element):
- ActionChains(self.driver).click(element).perform()
- def release(self, element):
- ActionChains(self.driver).release(element).perform()
- def refresh_click(self, data):
- for i in range(100):
- try:
- return self.click_simple(data)
- except StaleElementReferenceException:
- sleep(0.1)
- def refresh_xfind(self, path):
- for i in range(10):
- try:
- return self.driver.find_elements_by_xpath(path)
- except StaleElementReferenceException as ex:
- sleep(0.5)
- continue
- except Exception as ex:
- sleep(0.5)
- continue
- raise ex
- def refresh_idfind(self, id):
- for i in range(10):
- try:
- return self.driver.find_element_by_id(id)
- except StaleElementReferenceException as ex:
- sleep(0.5)
- except Exception as ex:
- sleep(0.5)
- raise ex
- if __name__ == '__main__':
- while True:
- try:
- WorkChecker(action=int(sys.argv[1]), user='', passw='').start()
- break
- except Exception:
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement