From 48889af5b185fa550b52fb30801b7eaea3cf017b Mon Sep 17 00:00:00 2001 From: fordprefect Date: Tue, 3 Aug 2021 21:14:13 +0200 Subject: [PATCH] automated file archiving to git --- coronavis.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/coronavis.py b/coronavis.py index 2b9cf7b..629219a 100644 --- a/coronavis.py +++ b/coronavis.py @@ -9,6 +9,7 @@ import numpy as np import sys import importlib import time +import subprocess sys.path.append(".") #### config @@ -86,6 +87,18 @@ def get_data(): with open(datafile, "wb") as f: f.write(r.content) + + ## file archiving: include error log just in case… + try: + subprocess.run(["/usr/bin/cp", f"../{date}-full-data.csv", "data.csv"], cwd="/srv/http/dukun.de/corona/data/git") + subprocess.run(["/usr/bin/git", "commit", "-a", f"-m'{date}'"], cwd="/srv/http/dukun.de/corona/data/git") + subprocess.run(["/usr/bin/git", "push"], cwd="/srv/http/dukun.de/corona/data/git") + except Exception as e: + print(f"File archiving failed with {e} - need for debugging here…") + print(e.with_traceback) + print("\n\n\ncontinuing…\n") + + else: print(f"file found: {datafile}")