diff --git a/Ferien.py b/Ferien.py index fca2af2..e38701d 100644 --- a/Ferien.py +++ b/Ferien.py @@ -2,22 +2,51 @@ import requests import json import time import datetime +import os +pfad = os.path.dirname(__file__) url_ferien ='http://api.smartnoob.de/ferien/v1/ferien/?bundesland=rp' url_feiertage = 'http://api.smartnoob.de/ferien/v1/feiertage/?bundesland=rp' -resp_ferien = requests.get(url_ferien) -resp_feiertage = requests.get(url_feiertage) +jetzt = time.strftime('%j') +tag = time.strftime('%d') -data_ferien = resp_ferien.json() -data_feiertage = resp_feiertage.json() +if int(tag) == 1: + print("Update Time!!!") + resp_ferien = requests.get(url_ferien) + resp_feiertage = requests.get(url_feiertage) + data_ferien = resp_ferien.json() + data_feiertage = resp_feiertage.json() + + with open(pfad + '/json_ferien.data', 'w') as outfile: + json.dump(data_ferien, outfile) + + with open(pfad + '/json_feiertage.data', 'w') as outfile: + json.dump(data_ferien, outfile) + +if os.path.isfile(pfad+'/json_ferien.data')!= True: + print('nicht da!!!') + + resp_ferien = requests.get(url_ferien) + resp_feiertage = requests.get(url_feiertage) + data_ferien = resp_ferien.json() + data_feiertage = resp_feiertage.json() + + with open(pfad+'/json_ferien.data','w') as outfile: + json.dump(data_ferien, outfile) + + with open(pfad+'/json_feiertage.data','w') as outfile: + json.dump(data_ferien, outfile) + +with open(pfad+'/json_ferien.data') as file: + data_ferien=json.load(file) +with open(pfad+'/json_feiertage.data') as file: + data_feiertage=json.load(file) a= len(data_ferien['daten']) x = 0 while x