initial commit
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
|
||||
from playwright.sync_api import BrowserContext, sync_playwright
|
||||
|
||||
|
||||
class creds:
|
||||
employee_id: str = "9374380"
|
||||
email: str = "abduessamet.kocak@refurbed.com"
|
||||
password: str = "^6LMq$LX&2#c4y"
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
day = datetime.date.today().fromisoformat(sys.argv[1]).isoformat()
|
||||
except:
|
||||
day = "today"
|
||||
|
||||
with sync_playwright() as playwright:
|
||||
data_dir = Path("/tmp/personio")
|
||||
data_dir.mkdir(exist_ok=True, parents=True)
|
||||
context = playwright.chromium.launch_persistent_context(headless=False, user_data_dir=data_dir)
|
||||
with context:
|
||||
fill_attendance(
|
||||
context=context,
|
||||
day=day,
|
||||
work=("08:00", "17:00"),
|
||||
pause=("12:00", "13:00"),
|
||||
)
|
||||
|
||||
|
||||
def fill_attendance(context: BrowserContext, day: str, work: tuple[str, str], pause=[str, str]):
|
||||
# Open new page
|
||||
page = context.new_page()
|
||||
|
||||
url = f"https://refurbed.personio.de/attendance/employee/{creds.employee_id}/"
|
||||
page.goto(url)
|
||||
page.wait_for_load_state()
|
||||
|
||||
if "/login/index" in page.url:
|
||||
page.locator('[placeholder="Email"]').fill(creds.email)
|
||||
page.locator('[placeholder="Password"]').fill(creds.password)
|
||||
page.locator('button:has-text("Login")').click()
|
||||
|
||||
card_selector = f'[data-test-id="day_{day}"] button'
|
||||
if day == "today":
|
||||
card_selector = '[data-test-id="today-cell"] button'
|
||||
|
||||
while True:
|
||||
page.locator(card_selector).click()
|
||||
if page.locator('[data-test-id="day-entry-dialog"]').is_visible():
|
||||
break
|
||||
time.sleep(0.05)
|
||||
|
||||
work_start, work_end = work
|
||||
page.locator('[data-test-id="timerange-start"]').first.fill(work_start)
|
||||
page.locator('[data-test-id="work-entry"] [data-test-id="timerange-end"]').fill(work_end)
|
||||
|
||||
pause_start, pause_end = pause
|
||||
page.locator('[data-test-id="break-entry"] [data-test-id="timerange-start"]').fill(pause_start)
|
||||
page.locator('[data-test-id="break-entry"] [data-test-id="timerange-end"]').fill(pause_end)
|
||||
|
||||
page.locator('[data-test-id="day-entry-save"]').click()
|
||||
# wait until network req is sent
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user