diff --git a/Mail.py b/Mail.py index 172757f..31ed955 100644 --- a/Mail.py +++ b/Mail.py @@ -1,9 +1,93 @@ import requests -import os +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' + +jetzt = int(time.strftime('%j')) +tag = time.strftime('%d') + +ferien = False +feiertag = False + +if os.path.isdir(pfad+'/mpg')!= True: #prüfen, ob das UNTERverzeichniss /mpg bereits existiert + os.makedirs(pfad+'/mpg') + print ('Downloadverzeichniss bei '+pfad +' /mpg/ created!!!') + +if int(tag) == 1: #Update einmal pro Monat + print("It´s 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_feiertage, outfile) + +if os.path.isfile(pfad+'/json_ferien.data')!= True: #Download der json, falls diese lokal nicht existieren + print('The json_xxx.datas not found, will try to download them from the API') + + 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_feiertage, 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 = beginn: + ferien = True + + x = x+1 + +a= len(data_feiertage['daten']) +x = 0 + +while x = beginn: + feiertag = True + + x = x+1 + +print('Es sind Ferien: '+ str(ferien)) +print('Es ist ein Feiertag: '+str(feiertag)) + def download(url): #return None filename = pfad+'/mpg/'+url+'.pdf' @@ -19,9 +103,6 @@ def modification_date(filename): t = os.path.getmtime(filename) return datetime.datetime.fromtimestamp(t) -if os.path.isdir(pfad+'/mpg')!= True: - os.makedirs(pfad+'/mpg') - print ('Downloadverzeichniss bei '+pfad +' /mpg/ created!!!') try: os.rename(pfad + '/mpg/heute.pdf', pfad +'/mpg/heute1.pdf')