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
|
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
|
# Variablen
|
||||||
key = 'e21758b9c711463552fb9c70ac7d4273'
|
key = 'e21758b9c711463552fb9c70ac7d4273'
|
||||||
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
|
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
|
||||||
@ -106,9 +119,10 @@ muell_arten = [
|
|||||||
'Schadstoffmobil',
|
'Schadstoffmobil',
|
||||||
]
|
]
|
||||||
|
|
||||||
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
|
||||||
|
|
||||||
# __main__
|
# __main__
|
||||||
|
antwort_liste = read_file(current_year)
|
||||||
|
if antwort_liste == None:
|
||||||
|
# Keine vernünftigen Daten, ergo mal gucken, was die Webseite ergibt
|
||||||
config = readConfig()
|
config = readConfig()
|
||||||
postdata['f_id_kommune'] = config['kommune']
|
postdata['f_id_kommune'] = config['kommune']
|
||||||
postdata['f_id_strasse'] = config['strasse']
|
postdata['f_id_strasse'] = config['strasse']
|
||||||
@ -121,20 +135,15 @@ http = httplib2.Http()
|
|||||||
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
|
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata))
|
||||||
|
|
||||||
antwort = str(content)
|
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')
|
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
|
|
||||||
|
|
||||||
daten = set(antwort_liste)
|
daten = set(antwort_liste)
|
||||||
|
|
||||||
for datum in daten:
|
for datum in daten:
|
||||||
|
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
|
||||||
datum = datum.split(';')
|
datum = datum.split(';')
|
||||||
l_muell = get_index_positions(datum, tomorrow)
|
l_muell = get_index_positions(datum, tomorrow)
|
||||||
if len(l_muell) > 0:
|
if len(l_muell) > 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user