init database

master
0x90.space 2021-12-28 06:11:42 +01:00
parent 7d67b59f5a
commit f32047b243
7 changed files with 46 additions and 13 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ __pycache__/
/.tox/ /.tox/
/build/ /build/
/venv/ /venv/
/db.sqlite3

View File

@ -1,4 +1,4 @@
Copyright (c) 2021 Thomas Lindner <tom@dl6tom.de> Copyright (c) 2021 0x90.space e.V. <people@schleuder.0x90.space>
Permission to use, copy, modify, and distribute this software for any Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above

View File

@ -1,14 +1,14 @@
[metadata] [metadata]
name = basicpy name = ticketfrei3
version = 0.0.1 version = 0.0.1
author = Thomas Lindner author = 0x90.space
author_email = tom@dl6tom.de author_email = people@schleuder.0x90.space
description = Basic python package description = Vermeidet Straftaten.
long_description = file: README.md long_description = file: README.md
long_description_content_type = text/markdown long_description_content_type = text/markdown
url = https://git.0x90.space/vmann/basicpy url = https://git.0x90.space/0x90/ticketfrei3
project_urls = project_urls =
Bug Tracker = https://git.0x90.space/vmann/basicpy/issues Bug Tracker = https://git.0x90.space/0x90/ticketfrei3/issues
classifiers = classifiers =
Programming Language :: Python :: 3 Programming Language :: Python :: 3
License :: OSI Approved :: ISC License (ISCL) License :: OSI Approved :: ISC License (ISCL)
@ -19,22 +19,23 @@ package_dir =
= src = src
packages = find: packages = find:
python_requires = >=3.8 python_requires = >=3.8
#install_requires = install_requires =
# dependency aiosqlite
blacksheep
tortoise-orm
[options.packages.find] [options.packages.find]
where = src where = src
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
basicpy = basicpy:main ticketfrei3 = ticketfrei3:main
[tox:tox] [tox:tox]
envlist = lint, py38, py39 envlist = lint, py38, py39
isolated_build = True isolated_build = True
[testenv:lint] [testenv:lint]
skip_install = True
deps = deps =
black black
flake8 flake8

View File

@ -1,2 +0,0 @@
def main() -> None:
print("Hello World")

View File

@ -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)

View File

@ -0,0 +1,7 @@
from tortoise.models import Model
from tortoise import fields
class Haltestelle(Model):
id = fields.IntField(pk=True)
name = fields.TextField()