You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
import toml
|
|
import os
|
|
import db_model as db
|
|
from peewee import SqliteDatabase, IntegrityError, PostgresqlDatabase
|
|
from sshtunnel import SSHTunnelForwarder
|
|
|
|
|
|
def config_laden():
|
|
configfile = os.path.join(SKRIPTPFAD, "config.toml")
|
|
with open(configfile) as file:
|
|
return toml.loads(file.read())
|
|
|
|
|
|
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
|
|
CONFIG = config_laden()
|
|
QUELLEN = ["jhu", "who", "rki"]
|
|
|
|
|
|
def country_umbennnen():
|
|
quelle = input("Quelle eingeben: ")
|
|
name_altes_land = input("Name der alten Bezeichnung des Landes eingeben: ")
|
|
name_neues_land = input("Name der neuen Bezeichnung des Landes eingeben: ")
|
|
|
|
try:
|
|
db.CoronaDaten.update(country_region=name_neues_land).where(
|
|
(db.CoronaDaten.country_region == name_altes_land) & (db.CoronaDaten.quelle == quelle)
|
|
).execute()
|
|
except IntegrityError:
|
|
db.CoronaDaten.delete().where(
|
|
(db.CoronaDaten.country_region == name_altes_land) & (db.CoronaDaten.quelle == quelle)
|
|
).execute()
|
|
|
|
|
|
def main():
|
|
with SSHTunnelForwarder(
|
|
(CONFIG["ssh"]["ip_server"], CONFIG["ssh"]["ssh_port"]), ssh_username=CONFIG["ssh"]["user"],
|
|
ssh_password=CONFIG["ssh"]["pw"], remote_bind_address=('127.0.0.1', CONFIG["pg"]["pgport"])) as server:
|
|
|
|
db.database.initialize(PostgresqlDatabase(CONFIG["pg"]["pgdb"],
|
|
user=CONFIG["pg"]["pguser"], password=CONFIG["pg"]["pgpw"],
|
|
host="127.0.0.1",
|
|
port=server.local_bind_port))
|
|
country_umbennnen()
|
|
|
|
|
|
main()
|