Compare commits

..

No commits in common. 'master' and 'develop' have entirely different histories.

  1. 27
      python/muell.py

27
python/muell.py

@ -45,7 +45,7 @@ def readConfig():
home = Path.home() # home ist ohne / am Ende! home = Path.home() # home ist ohne / am Ende!
config = {} config = {}
with open(f'{home}/.muell.yaml', 'r') as config_file: with open(f'{home}/.muell.yaml', 'r') as config_file:
config = yaml.safe_load(config_file) config = yaml.load(config_file)
return config return config
@ -75,7 +75,6 @@ def read_file(jahr):
''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück''' ''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
antwort_liste = list() antwort_liste = list()
headline = list()
try: try:
with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f: with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f:
csv_reader = csv.reader(f, delimiter=';') csv_reader = csv.reader(f, delimiter=';')
@ -84,7 +83,6 @@ def read_file(jahr):
for row in csv_reader: for row in csv_reader:
if lines == 0: if lines == 0:
# print(f'Column names are {", ".join(row)}') # print(f'Column names are {", ".join(row)}')
headline = row
lines += 1 lines += 1
else: else:
if isinstance(row, list): if isinstance(row, list):
@ -92,7 +90,7 @@ def read_file(jahr):
except FileNotFoundError: except FileNotFoundError:
pass pass
return (antwort_liste, headline) return antwort_liste
# Variablen # Variablen
key = 'e21758b9c711463552fb9c70ac7d4273' key = 'e21758b9c711463552fb9c70ac7d4273'
@ -113,7 +111,7 @@ postdata = {
'f_id_abfalltyp_3': '187', 'f_id_abfalltyp_3': '187',
'f_id_abfalltyp_4': '169', 'f_id_abfalltyp_4': '169',
'f_abfallarten_index_max': '5', 'f_abfallarten_index_max': '5',
'f_abfallarten': '50,161,53,187', 'f_abfallarten': '50,161,53,187,169',
'f_zeitraum': zeitraum, 'f_zeitraum': zeitraum,
'f_export_als': export_als, 'f_export_als': export_als,
} }
@ -123,8 +121,16 @@ headers = {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
} }
muell_arten = [
'Gelbe Tonne',
'Biomüll',
'Papiermüll',
'Restmüll',
'Schadstoffmobil',
]
if __name__ == '__main__': if __name__ == '__main__':
(antwort_liste, headline) = read_file(current_year) antwort_liste = read_file(current_year)
config = readConfig() config = readConfig()
if not antwort_liste: if not antwort_liste:
@ -143,17 +149,12 @@ if __name__ == '__main__':
f = open(f'muell{current_year}.csv', 'wb') f = open(f'muell{current_year}.csv', 'wb')
f.write(content) f.write(content)
f.close() f.close()
(antwort_liste, headline) = read_file(current_year) antwort_liste = read_file(current_year)
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y') tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
index = set(); index = set();
for row in antwort_liste: for row in antwort_liste:
try: try:
if (row.count(tomorrow) > 1):
for i in range(len(row)):
if (row[i] == tomorrow and i < 4):
index.add(i)
else:
pos = row.index(tomorrow) pos = row.index(tomorrow)
if pos < 4: if pos < 4:
index.add(pos) index.add(pos)
@ -163,7 +164,7 @@ if __name__ == '__main__':
wird = 'wird' if len(index) < 2 else 'werden' wird = 'wird' if len(index) < 2 else 'werden'
tonnen = [] tonnen = []
for pos in index: for pos in index:
tonnen.append(headline[pos]) tonnen.append(muell_arten[pos])
if len(tonnen) > 0: if len(tonnen) > 0:
tonnen = ' und '.join(tonnen) tonnen = ' und '.join(tonnen)

Loading…
Cancel
Save