From bff28dba4fe6026ba025121faea0c3c442b9776f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=B6hme?= Date: Thu, 2 Jul 2020 19:51:18 +0200 Subject: [PATCH] added daily download of the CWA config file (#6) --- .gitignore | 1 + data_CWA/app_config/app_config_2020-07-02.bin | Bin 0 -> 241 bytes data_CWA/app_config/app_config_2020-07-02.sig | Bin 0 -> 135 bytes scripts/CWA_app_config.py | 53 ++++++++++++++++++ update_all.sh | 1 + 5 files changed, 55 insertions(+) create mode 100644 data_CWA/app_config/app_config_2020-07-02.bin create mode 100644 data_CWA/app_config/app_config_2020-07-02.sig create mode 100755 scripts/CWA_app_config.py diff --git a/.gitignore b/.gitignore index be7419b9c..8ab1cc30c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ data_RKI/cwa_statistics.ods data_CWA/*.zip +data_CWA/app_config/*.zip diff --git a/data_CWA/app_config/app_config_2020-07-02.bin b/data_CWA/app_config/app_config_2020-07-02.bin new file mode 100644 index 0000000000000000000000000000000000000000..85aba84458eb4a2b93821891bf4aa59377418360 GIT binary patch literal 241 zcmdfJuT`fklJWfX#y4fkTi13_KmAxD*&Q7!4RL7#$cDVS-u$9IOJY z608cWK=rH^tPZS(5GfM}D?R~62}Xn-N0=TZ87>wMa{+rHAx?0M^(ESIiJ(8L_26@bbNTJD#{6=HF!2BY literal 0 HcmV?d00001 diff --git a/scripts/CWA_app_config.py b/scripts/CWA_app_config.py new file mode 100755 index 000000000..bdbd2a267 --- /dev/null +++ b/scripts/CWA_app_config.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import datetime, requests, os, sys + + +def downloadAppConfig(data_dir, datestr): + DOWNLOAD_URL = "https://svc90.main.px.t-online.de/version/v1/configuration/country/DE/app_config" + ZIP_FILE = "app_config_" + datestr + ".zip" + BIN_FILE = "app_config_" + datestr + ".bin" + SIG_FILE = "app_config_" + datestr + ".sig" + DATAFILE = data_dir + ZIP_FILE + + try: + headers = { 'Pragma': 'no-cache', 'Cache-Control': 'no-cache' } + r = requests.get(DOWNLOAD_URL, headers=headers, allow_redirects=True, timeout=5.0, stream=True) + + if r.status_code == 200: + if ( len(r.content) > 1 ): + + # write zip file + f = open(DATAFILE, 'wb') + f.write(r.content) + f.close() + + # unzip and rename files + os.system("(cd {} && unzip {} > /dev/null && mv export.bin {} && mv export.sig {})".format(data_dir, ZIP_FILE, BIN_FILE, SIG_FILE)) + + return True + return False + except: + return False + + +if __name__ == "__main__": + + ########################################################################### + ##### Paths and filenames + ########################################################################### + CFG_DATA_DIR = os.path.dirname(os.path.realpath(__file__)) + "/../data_CWA/app_config/" + + today_str = datetime.datetime.now().strftime("%Y-%m-%d") + + # download daily app config + app_config = downloadAppConfig(CFG_DATA_DIR, today_str) + + # stop immediately if download failed + if ( app_config == False ): + print("Error! Could not download app_config!") + sys.exit(1) + + # more analysis of binary app_config + # ((...)) + \ No newline at end of file diff --git a/update_all.sh b/update_all.sh index 0cf719213..77530da4e 100755 --- a/update_all.sh +++ b/update_all.sh @@ -8,6 +8,7 @@ cd scripts ./CWA_RKI_users.py > /dev/null ./CWA_JHU_users.py > /dev/null ./CWA_TRL_daily_dist.py > /dev/null +./CWA_app_config.py > /dev/null cd .. # update plots