-
Notifications
You must be signed in to change notification settings - Fork 0
/
woffu.py
executable file
·65 lines (47 loc) · 2 KB
/
woffu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -------------------------------------------------------------------
# Set a cronjob 5 minutes before you clock-in/out
# running this script and forget about using Woffu :)
# -------------------------------------------------------------------
import os
import time
import random
import argparse
import logging
from logging.handlers import TimedRotatingFileHandler
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
logging_handler = TimedRotatingFileHandler(filename='woffu.log', when='D', interval=30)
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.INFO, handlers=[logging_handler])
parser = argparse.ArgumentParser()
parser.add_argument('--action', type=str, required=True, dest='action', choices=['entrada', 'salida'])
args = parser.parse_args()
action = args.action
# --------------------------------------------
URL = f'https://{os.environ('WOFFU_COMPANY')}.woffu.com/#/login'
EMAIL = os.environ('WOFFU_EMAIL')
PASSWORD = os.environ('WOFFU_PASS')
# --------------------------------------------
# To avoid clock-in/out always at the same exact time
random_mins = random.randint(3, 6) * 60
time.sleep(random_mins)
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', chrome_options=chrome_options)
wait = WebDriverWait(driver, 10)
driver.get(URL)
# Log in
email = driver.find_element_by_id("tuEmail")
password = driver.find_element_by_id("tuPassword")
email.send_keys(EMAIL)
password.send_keys(PASSWORD)
driver.find_element_by_xpath('//*[@id="intro"]/div/form/span/button').click()
# Wait until the page is loaded
wait.until(lambda driver: driver.find_element_by_class_name('progress-bar'))
if action == 'entrada':
driver.find_element_by_id("in").click()
logging.info('Entrada')
elif action == 'salida':
driver.find_element_by_id("out").click()
logging.info('Salida')
driver.quit()