Skip to content

Commit

Permalink
added daily download of the CWA config file (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
micb25 committed Jul 2, 2020
1 parent 9483a2c commit bff28db
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
data_RKI/cwa_statistics.ods
data_CWA/*.zip
data_CWA/app_config/*.zip
Binary file added data_CWA/app_config/app_config_2020-07-02.bin
Binary file not shown.
Binary file added data_CWA/app_config/app_config_2020-07-02.sig
Binary file not shown.
53 changes: 53 additions & 0 deletions scripts/CWA_app_config.py
Original file line number Diff line number Diff line change
@@ -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
# ((...))

1 change: 1 addition & 0 deletions update_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bff28db

Please sign in to comment.