Compare commits

...

4 Commits

  1. 1
      .gitignore
  2. 43
      python/muell.py

1
.gitignore vendored

@ -1 +1,2 @@
*.csv
__pycache__

43
python/muell.py

@ -15,6 +15,10 @@ kommune: 2601
strasse: 2146
pathBot: '~/bin/YMBot'
tgBotOwner: <hier DEINE Telegram-ID eintragen>
signal:
path: "~/bin/signal-cli"
account: "+49<deine Mobilfunknummer>"
group_id: "<siehe 'signal-cli listGroups'>"
'''
import csv
@ -45,7 +49,7 @@ def readConfig():
home = Path.home() # home ist ohne / am Ende!
config = {}
with open(f'{home}/.muell.yaml', 'r') as config_file:
config = yaml.load(config_file)
config = yaml.safe_load(config_file)
return config
@ -75,6 +79,7 @@ def read_file(jahr):
''' Liest Daten aus muell<jahr>.csv und liefert ggf. Ergebnis zurück'''
antwort_liste = list()
headline = list()
try:
with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f:
csv_reader = csv.reader(f, delimiter=';')
@ -83,6 +88,7 @@ def read_file(jahr):
for row in csv_reader:
if lines == 0:
# print(f'Column names are {", ".join(row)}')
headline = row
lines += 1
else:
if isinstance(row, list):
@ -90,7 +96,7 @@ def read_file(jahr):
except FileNotFoundError:
pass
return antwort_liste
return (antwort_liste, headline)
# Variablen
key = 'e21758b9c711463552fb9c70ac7d4273'
@ -111,7 +117,7 @@ postdata = {
'f_id_abfalltyp_3': '187',
'f_id_abfalltyp_4': '169',
'f_abfallarten_index_max': '5',
'f_abfallarten': '50,161,53,187,169',
'f_abfallarten': '50,161,53,187',
'f_zeitraum': zeitraum,
'f_export_als': export_als,
}
@ -121,16 +127,8 @@ headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
muell_arten = [
'Gelbe Tonne',
'Biomüll',
'Papiermüll',
'Restmüll',
'Schadstoffmobil',
]
if __name__ == '__main__':
antwort_liste = read_file(current_year)
(antwort_liste, headline) = read_file(current_year)
config = readConfig()
if not antwort_liste:
@ -149,24 +147,35 @@ if __name__ == '__main__':
f = open(f'muell{current_year}.csv', 'wb')
f.write(content)
f.close()
antwort_liste = read_file(current_year)
(antwort_liste, headline) = read_file(current_year)
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
index = set();
for row in antwort_liste:
try:
pos = row.index(tomorrow)
if pos < 4:
index.add(pos)
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)
if pos < 4:
index.add(pos)
except ValueError:
pass
wird = 'wird' if len(index) < 2 else 'werden'
tonnen = []
for pos in index:
tonnen.append(muell_arten[pos])
tonnen.append(headline[pos])
if len(tonnen) > 0:
tonnen = ' und '.join(tonnen)
# Jetzt den Bot ansprechen
os.system(f'echo "Morgen {wird} {tonnen} abgeholt" | {config["pathBot"]} -u {config["tgReceiver"]}')
# Signal Bot
try:
os.system(f'{config["signal"]["path"]} -a {config["signal"]["account"]} send -g {config["signal"]["group_id"]} -m "Morgen {wird} {tonnen} abgeholt"')
except NameError:
pass

Loading…
Cancel
Save