Ablauf verbessert
This commit is contained in:
parent
69b0311f9f
commit
13716aa464
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.csv
|
@ -69,6 +69,19 @@ def init(key, modus, host, headers):
|
||||
|
||||
return name, value
|
||||
|
||||
def read_file(jahr):
|
||||
''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
|
||||
|
||||
antwort_liste = None
|
||||
try:
|
||||
f = open(f'muell{jahr}.csv', 'rb')
|
||||
antwort = str(f.read())
|
||||
antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
return antwort_liste
|
||||
|
||||
# Variablen
|
||||
key = 'e21758b9c711463552fb9c70ac7d4273'
|
||||
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
|
||||
@ -106,35 +119,31 @@ muell_arten = [
|
||||
'Schadstoffmobil',
|
||||
]
|
||||
|
||||
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
||||
|
||||
# __main__
|
||||
config = readConfig()
|
||||
postdata['f_id_kommune'] = config['kommune']
|
||||
postdata['f_id_strasse'] = config['strasse']
|
||||
antwort_liste = read_file(current_year)
|
||||
if antwort_liste == None:
|
||||
# Keine vernünftigen Daten, ergo mal gucken, was die Webseite ergibt
|
||||
config = readConfig()
|
||||
postdata['f_id_kommune'] = config['kommune']
|
||||
postdata['f_id_strasse'] = config['strasse']
|
||||
|
||||
(name, value) = init(key, modus, host, headers)
|
||||
if name != None and value != None:
|
||||
postdata[name] = value
|
||||
(name, value) = init(key, modus, host, headers)
|
||||
if name != None and value != None:
|
||||
postdata[name] = value
|
||||
|
||||
http = httplib2.Http()
|
||||
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
|
||||
http = httplib2.Http()
|
||||
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
|
||||
|
||||
antwort = str(content)
|
||||
antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
|
||||
|
||||
if antwort_liste[0] == '':
|
||||
# Keine vernünftigen Daten, ergo mal gucken, was in der Datei steht
|
||||
try:
|
||||
f = open('muell.csv', 'rb')
|
||||
antwort = str(f.read())
|
||||
antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
antwort = str(content)
|
||||
f = open(f'muell{current_year}.csv', 'wb')
|
||||
f.write(content)
|
||||
f.close()
|
||||
antwort_liste = antwort[antwort.find('Biom'):].strip("'").replace('\\n', '\n').split('\n')
|
||||
|
||||
daten = set(antwort_liste)
|
||||
|
||||
for datum in daten:
|
||||
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
||||
datum = datum.split(';')
|
||||
l_muell = get_index_positions(datum, tomorrow)
|
||||
if len(l_muell) > 0:
|
||||
|
Loading…
Reference in New Issue
Block a user