Use with for database connection

This commit is contained in:
clerie 2022-02-28 17:05:14 +01:00
parent cf620b86bc
commit bf638d84f3
1 changed files with 86 additions and 89 deletions

View File

@ -16,8 +16,8 @@ class DwdScraper:
return v
conn = psycopg2.connect(config_db["uri"])
cur = conn.cursor()
with psycopg2.connect(config_db["uri"]) as conn:
with conn.cursor() as cur:
cur.execute("SELECT min(dwd_last_update) FROM stations;")
last_date = cur.fetchall()[0][0]
@ -109,8 +109,5 @@ class DwdScraper:
conn.commit()
cur.close()
conn.close()
if __name__ == "__main__":
DwdScraper().run()