61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
import re
|
|
from playwright.sync_api import Playwright, sync_playwright, expect
|
|
import time
|
|
|
|
import loguru
|
|
import sys
|
|
|
|
log = loguru.logger
|
|
log.remove()
|
|
log.add("management.log", rotation="1 week", retention="1 month")
|
|
log.add(sys.stdout)
|
|
|
|
|
|
def run(playwright: Playwright) -> None:
|
|
browser = playwright.chromium.launch(headless=False)
|
|
context = browser.new_context()
|
|
page = context.new_page()
|
|
page.goto("https://lsf.ph-freiburg.de/qisfsvfr/rds?state=user&type=0")
|
|
page.get_by_label("Benutzerkennung").click()
|
|
page.get_by_label("Benutzerkennung").fill(USER)
|
|
page.get_by_label("Passwort").click()
|
|
page.get_by_label("Passwort").fill(PASSWORD)
|
|
page.get_by_role("button", name="Anmelden").click()
|
|
page.get_by_role("link", name="Zeiterfassung").click()
|
|
page.locator("#makronavigation").get_by_role("link", name="Zeiterfassung").click()
|
|
time.sleep(1)
|
|
get_overtime(page)
|
|
|
|
context.close()
|
|
browser.close()
|
|
|
|
|
|
def get_overtime(page):
|
|
table = (
|
|
page.get_by_role("cell", name="Überstunden:", exact=False)
|
|
.get_by_role("table")
|
|
.first
|
|
)
|
|
rows = table.locator("tr").all()
|
|
|
|
# Extract data from each row
|
|
for row in rows:
|
|
cells = row.locator("td").all_text_contents()
|
|
celltext = " ".join(cells)
|
|
if "Aktuell" in celltext and "Stunden" in celltext:
|
|
continue
|
|
elif "Aktuell" in celltext:
|
|
# get the time, can be negative or positive with : for hh:mm
|
|
# regex to find the time in the string
|
|
match = re.search(r"[-+]?\d{1,3}:\d{2}", celltext)
|
|
if match:
|
|
# Extract the time string
|
|
time_str = match.group()
|
|
return time_str
|
|
else:
|
|
return 0
|
|
|
|
|
|
with sync_playwright() as playwright:
|
|
run(playwright)
|