init database
This commit is contained in:
parent
7d67b59f5a
commit
f32047b243
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ __pycache__/
|
|||
/.tox/
|
||||
/build/
|
||||
/venv/
|
||||
/db.sqlite3
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -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
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
21
setup.cfg
21
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
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
def main() -> None:
|
||||
print("Hello World")
|
26
src/ticketfrei3/__init__.py
Normal file
26
src/ticketfrei3/__init__.py
Normal 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)
|
7
src/ticketfrei3/models.py
Normal file
7
src/ticketfrei3/models.py
Normal 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()
|
Loading…
Reference in a new issue