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