From f0caaea20e843ba4b5acad553862d81837c4fd1c Mon Sep 17 00:00:00 2001 From: eneller Date: Sun, 13 Apr 2025 17:41:50 +0200 Subject: [PATCH] feat: click cli --- main.py | 28 +++++++++++++++++++--------- pyproject.toml | 1 + uv.lock | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 1f123d6..957a263 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,20 @@ -import asyncio -from time import sleep +import asyncclick as click import questionary from playwright.async_api import async_playwright, Playwright -import re -async def run(playwright: Playwright) -> None: - username = await questionary.text('Enter your kiz username:').ask_async() - password = await questionary.password('Enter your kiz password:').ask_async() - browser = await playwright.chromium.launch(headless=False) +import re +import asyncio +from time import sleep + +async def run( + playwright: Playwright, + username, + password, + headless:bool, + ) -> None: + if not username: username = await questionary.text('Enter your kiz username:').ask_async() + if not password: password = await questionary.password('Enter your kiz password:').ask_async() + browser = await playwright.chromium.launch(headless=headless) context = await browser.new_context() page = await context.new_page() await page.goto("https://campusonline.uni-ulm.de") @@ -34,9 +41,12 @@ async def run(playwright: Playwright) -> None: await context.close() await browser.close() -async def main(): +@click.command() +@click.option('--username','-u') +@click.option('--password','-p') +async def main(username, password): async with async_playwright() as playwright: - await run(playwright) + await run(playwright, username, password, True) if __name__ == "__main__": asyncio.run(main()) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index abda138..62bc9e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,6 +5,7 @@ description = "Add your description here" readme = "README.md" requires-python = ">=3.12" dependencies = [ + "asyncclick>=8.1.8", "click>=8.1.8", "playwright>=1.51.0", "questionary>=2.1.0", diff --git a/uv.lock b/uv.lock index bd1de5b..2d96035 100644 --- a/uv.lock +++ b/uv.lock @@ -2,11 +2,40 @@ version = 1 revision = 1 requires-python = ">=3.12" +[[package]] +name = "anyio" +version = "4.9.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "idna" }, + { name = "sniffio" }, + { name = "typing-extensions", marker = "python_full_version < '3.13'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/95/7d/4c1bd541d4dffa1b52bd83fb8527089e097a106fc90b467a7313b105f840/anyio-4.9.0.tar.gz", hash = "sha256:673c0c244e15788651a4ff38710fea9675823028a6f08a5eda409e0c9840a028", size = 190949 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a1/ee/48ca1a7c89ffec8b6a0c5d02b89c305671d5ffd8d3c94acf8b8c408575bb/anyio-4.9.0-py3-none-any.whl", hash = "sha256:9f76d541cad6e36af7beb62e978876f3b41e3e04f2c1fbf0884604c0a9c4d93c", size = 100916 }, +] + +[[package]] +name = "asyncclick" +version = "8.1.8" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "anyio" }, + { name = "colorama", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/cb/b5/e1e5fdf1c1bb7e6e614987c120a98d9324bf8edfaa5f5cd16a6235c9d91b/asyncclick-8.1.8.tar.gz", hash = "sha256:0f0eb0f280e04919d67cf71b9fcdfb4db2d9ff7203669c40284485c149578e4c", size = 232900 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/14/cc/a436f0fc2d04e57a0697e0f87a03b9eaed03ad043d2d5f887f8eebcec95f/asyncclick-8.1.8-py3-none-any.whl", hash = "sha256:eb1ccb44bc767f8f0695d592c7806fdf5bd575605b4ee246ffd5fadbcfdbd7c6", size = 99093 }, + { url = "https://files.pythonhosted.org/packages/92/c4/ae9e9d25522c6dc96ff167903880a0fe94d7bd31ed999198ee5017d977ed/asyncclick-8.1.8.0-py3-none-any.whl", hash = "sha256:be146a2d8075d4fe372ff4e877f23c8b5af269d16705c1948123b9415f6fd678", size = 99115 }, +] + [[package]] name = "campus-search" version = "0.1.0" source = { virtual = "." } dependencies = [ + { name = "asyncclick" }, { name = "click" }, { name = "playwright" }, { name = "questionary" }, @@ -14,6 +43,7 @@ dependencies = [ [package.metadata] requires-dist = [ + { name = "asyncclick", specifier = ">=8.1.8" }, { name = "click", specifier = ">=8.1.8" }, { name = "playwright", specifier = ">=1.51.0" }, { name = "questionary", specifier = ">=2.1.0" }, @@ -73,6 +103,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ac/38/08cc303ddddc4b3d7c628c3039a61a3aae36c241ed01393d00c2fd663473/greenlet-3.1.1-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:411f015496fec93c1c8cd4e5238da364e1da7a124bcb293f085bf2860c32c6f6", size = 1142112 }, ] +[[package]] +name = "idna" +version = "3.10" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/f1/70/7703c29685631f5a7590aa73f1f1d3fa9a380e654b86af429e0934a32f7d/idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9", size = 190490 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl", hash = "sha256:946d195a0d259cbba61165e88e65941f16e9b36ea6ddb97f00452bae8b1287d3", size = 70442 }, +] + [[package]] name = "playwright" version = "1.51.0" @@ -127,6 +166,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ad/3f/11dd4cd4f39e05128bfd20138faea57bec56f9ffba6185d276e3107ba5b2/questionary-2.1.0-py3-none-any.whl", hash = "sha256:44174d237b68bc828e4878c763a9ad6790ee61990e0ae72927694ead57bab8ec", size = 36747 }, ] +[[package]] +name = "sniffio" +version = "1.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 }, +] + [[package]] name = "typing-extensions" version = "4.13.2"