feat: check server time

This commit is contained in:
eneller
2025-04-14 03:22:27 +02:00
parent fb7f0c8ea8
commit 82d87ba771

View File

@@ -7,6 +7,7 @@ from enum import Enum
import asyncio import asyncio
from time import sleep from time import sleep
import logging import logging
from datetime import datetime
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -46,11 +47,13 @@ async def cli(ctx, username, password, headful, debug):
ctx.obj['PASSWORD'] = password or await questionary.password('Enter your kiz password:').ask_async() ctx.obj['PASSWORD'] = password or await questionary.password('Enter your kiz password:').ask_async()
ctx.obj['HEADLESS'] = not headful ctx.obj['HEADLESS'] = not headful
@cli.command(help='Interact with the module tree in Campusonline') @cli.command()
@click.pass_context @click.pass_context
async def campusonline(ctx): async def campusonline(ctx):
'''
Interact with the module tree in Campusonline.
'''
async for page, browser, context in run_playwright(ctx.obj['HEADLESS']): async for page, browser, context in run_playwright(ctx.obj['HEADLESS']):
click.echo("Running campusonline...")
await page.goto("https://campusonline.uni-ulm.de") await page.goto("https://campusonline.uni-ulm.de")
await page.get_by_role("textbox", name="Benutzerkennung").click() await page.get_by_role("textbox", name="Benutzerkennung").click()
await page.get_by_role("textbox", name="Benutzerkennung").fill(ctx.obj['USERNAME']) await page.get_by_role("textbox", name="Benutzerkennung").fill(ctx.obj['USERNAME'])
@@ -62,18 +65,32 @@ async def campusonline(ctx):
selection = await selection_or_walk(options) selection = await selection_or_walk(options)
print(selection) print(selection)
sleep(2) sleep(2)
click.echo("Finished campusonline.")
@cli.command(help='Automatically register for courses on CoronaNG') @cli.command()
@click.argument('times', nargs=-1, required=True)
@click.option('--before', '-b', type=int, default=10, help='How many seconds before the target time to start')
@click.pass_context @click.pass_context
async def coronang(ctx): async def coronang(ctx, times, before):
'''
Automatically register for courses on CoronaNG by specifying one or more timestamps of the format "HH:MM:SS".
Please beware that CoronaNG only allows one active session at all times.
'''
target_times = sorted([datetime.strptime(t, "%H:%M:%S") for t in times])
logger.info('Parsed input times as %s', target_times)
async for page, browser, context in run_playwright(ctx.obj['HEADLESS']): async for page, browser, context in run_playwright(ctx.obj['HEADLESS']):
click.echo("Running coronang...")
await page.goto("https://campusonline.uni-ulm.de/CoronaNG/user/mycorona.html") await page.goto("https://campusonline.uni-ulm.de/CoronaNG/user/mycorona.html")
version = await page.locator("css=#mblock_innen > a:nth-child(1)").inner_text() server_version = await page.locator("css=#mblock_innen > a:nth-child(1)").inner_text()
if(version != CORONANG_VERSION): if(server_version != CORONANG_VERSION):
logger.warning('Read CoronaNG version %s. Last tested version is %s. Please use --headful flag to ensure that everything is working.', logger.warning('Read CoronaNG version %s. Last tested version is %s. Please use --headful flag to ensure that everything is working.',
version, CORONANG_VERSION) server_version, CORONANG_VERSION)
for target_time in target_times:
while True:
server_str = await page.locator("css=#mblock_innen").inner_text()
server_time = datetime.strptime(server_str.split().pop(), "%H:%M:%S")
break
exit()
await page.locator("input[name=\"uid\"]").click() await page.locator("input[name=\"uid\"]").click()
await page.locator("input[name=\"uid\"]").fill(ctx.obj['USERNAME']) await page.locator("input[name=\"uid\"]").fill(ctx.obj['USERNAME'])
await page.locator("input[name=\"password\"]").click() await page.locator("input[name=\"password\"]").click()
@@ -84,12 +101,15 @@ async def coronang(ctx):
await page.get_by_role("table", name="Ihre Beobachtungen. Sie kö").get_by_role("combobox").select_option("5") await page.get_by_role("table", name="Ihre Beobachtungen. Sie kö").get_by_role("combobox").select_option("5")
await page.get_by_role("cell", name="An Markierten teilnehmen Ausf").get_by_role("button").click() await page.get_by_role("cell", name="An Markierten teilnehmen Ausf").get_by_role("button").click()
await page.reload() await page.reload()
click.echo("Finished coronang.")
@cli.command(help='''Calculate your weighted grade using the best n credits. Expects a csv with the columns name, grade, credits''') @cli.command()
@click.argument('filename', type=click.Path(exists=True)) @click.argument('filename', type=click.Path(exists=True))
@click.option('--target_lp', '-t', type=int, default=74, help='Target number of n credits needed') @click.option('--target_lp', '-t', type=int, default=74, help='Target number of n credits needed')
def grades(filename, target_lp:int): def grades(filename, target_lp:int):
'''
Calculate your weighted grade using the best n credits.
Expects a csv with the columns "name, grade, credits".
'''
data = pd.read_csv(filename) data = pd.read_csv(filename)
data.sort_values(by='grade', inplace=True) data.sort_values(by='grade', inplace=True)