From f32047b24303f4afdec1487dc35613ad2a813ed8 Mon Sep 17 00:00:00 2001 From: "0x90.space" Date: Tue, 28 Dec 2021 06:11:42 +0100 Subject: [PATCH] init database --- .gitignore | 1 + LICENSE | 2 +- setup.cfg | 21 ++++++++++--------- src/basicpy/__init__.py | 2 -- src/ticketfrei3/__init__.py | 26 ++++++++++++++++++++++++ src/{basicpy => ticketfrei3}/__main__.py | 0 src/ticketfrei3/models.py | 7 +++++++ 7 files changed, 46 insertions(+), 13 deletions(-) delete mode 100644 src/basicpy/__init__.py create mode 100644 src/ticketfrei3/__init__.py rename src/{basicpy => ticketfrei3}/__main__.py (100%) create mode 100644 src/ticketfrei3/models.py diff --git a/.gitignore b/.gitignore index 7c463ec..f922544 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ /.tox/ /build/ /venv/ +/db.sqlite3 diff --git a/LICENSE b/LICENSE index 12b9019..345b23b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2021 Thomas Lindner +Copyright (c) 2021 0x90.space e.V. Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/setup.cfg b/setup.cfg index 41fc17f..8b13767 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,14 +1,14 @@ [metadata] -name = basicpy +name = ticketfrei3 version = 0.0.1 -author = Thomas Lindner -author_email = tom@dl6tom.de -description = Basic python package +author = 0x90.space +author_email = people@schleuder.0x90.space +description = Vermeidet Straftaten. long_description = file: README.md long_description_content_type = text/markdown -url = https://git.0x90.space/vmann/basicpy +url = https://git.0x90.space/0x90/ticketfrei3 project_urls = - Bug Tracker = https://git.0x90.space/vmann/basicpy/issues + Bug Tracker = https://git.0x90.space/0x90/ticketfrei3/issues classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: ISC License (ISCL) @@ -19,22 +19,23 @@ package_dir = = src packages = find: python_requires = >=3.8 -#install_requires = -# dependency +install_requires = + aiosqlite + blacksheep + tortoise-orm [options.packages.find] where = src [options.entry_points] console_scripts = - basicpy = basicpy:main + ticketfrei3 = ticketfrei3:main [tox:tox] envlist = lint, py38, py39 isolated_build = True [testenv:lint] -skip_install = True deps = black flake8 diff --git a/src/basicpy/__init__.py b/src/basicpy/__init__.py deleted file mode 100644 index 9169e98..0000000 --- a/src/basicpy/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -def main() -> None: - print("Hello World") diff --git a/src/ticketfrei3/__init__.py b/src/ticketfrei3/__init__.py new file mode 100644 index 0000000..3938631 --- /dev/null +++ b/src/ticketfrei3/__init__.py @@ -0,0 +1,26 @@ +import asyncio +from blacksheep.client import ClientSession +import json +from ticketfrei3.models import Haltestelle +from tortoise import Tortoise + + +async def asyncmain() -> None: + await Tortoise.init( + db_url="sqlite://db.sqlite3", modules={"models": ["ticketfrei3.models"]} + ) + await Tortoise.generate_schemas() + async with ClientSession(connection_timeout=30) as client: + response = await client.get("https://start.vag.de/dm/api/haltestellen.json/vag") + haltestellen = json.loads(await response.text()) + for haltestelle in haltestellen["Haltestellen"]: + if not await Haltestelle.exists(id=haltestelle["VGNKennung"]): + await Haltestelle.create( + id=haltestelle["VGNKennung"], + name=haltestelle["Haltestellenname"], + ) + await Tortoise.close_connections() + + +def main() -> None: + asyncio.run(asyncmain(), debug=True) diff --git a/src/basicpy/__main__.py b/src/ticketfrei3/__main__.py similarity index 100% rename from src/basicpy/__main__.py rename to src/ticketfrei3/__main__.py diff --git a/src/ticketfrei3/models.py b/src/ticketfrei3/models.py new file mode 100644 index 0000000..22faeb2 --- /dev/null +++ b/src/ticketfrei3/models.py @@ -0,0 +1,7 @@ +from tortoise.models import Model +from tortoise import fields + + +class Haltestelle(Model): + id = fields.IntField(pk=True) + name = fields.TextField()