|
|
|
@ -10,13 +10,14 @@ Um die Daten an Telegram zu senden, musst du dir ein Skript/Programm schreiben,
|
|
|
|
|
von Telegram verwendet und Daten an dich oder deine Gruppe senden kann! |
|
|
|
|
|
|
|
|
|
Beispiel für eine Konfigurationsdatei: |
|
|
|
|
tgReceiver: <hier die ID der Gruppe/ des Teilnhemers eintragen> |
|
|
|
|
tgReceiver: <hier die ID der Gruppe/ des Teilnehmers eintragen> |
|
|
|
|
kommune: 2601 |
|
|
|
|
strasse: 2146 |
|
|
|
|
pathBot: '~/bin/YMBot' |
|
|
|
|
tgBotOwner: <hier DEINE Telegram-ID eintragen> |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
import csv |
|
|
|
|
import re |
|
|
|
|
import requests |
|
|
|
|
import httplib2 |
|
|
|
@ -28,7 +29,7 @@ from pathlib import Path
|
|
|
|
|
|
|
|
|
|
# Funktionen |
|
|
|
|
def get_index_positions(list_of_elems, element): |
|
|
|
|
''' Returns the indexes of all occurrences of give element in |
|
|
|
|
''' Returns the indexes of all occurrences of given element in |
|
|
|
|
the list- listOfElements ''' |
|
|
|
|
index_pos_list = [] |
|
|
|
|
for i in range(len(list_of_elems)): |
|
|
|
@ -53,7 +54,7 @@ def init(key, modus, host, headers):
|
|
|
|
|
url = f'https://{host}/?key={key}&modus={modus}&waction=init' |
|
|
|
|
http = httplib2.Http() |
|
|
|
|
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(postdata)) |
|
|
|
|
# print(content) |
|
|
|
|
|
|
|
|
|
result = re.findall(r"<input .*?name=.*? value=.*?/>", str(content)) |
|
|
|
|
|
|
|
|
|
datum = result[1].split(' ') |
|
|
|
@ -74,9 +75,17 @@ def read_file(jahr):
|
|
|
|
|
|
|
|
|
|
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') |
|
|
|
|
with open(f'muell{jahr}.csv', 'r', encoding="latin1") as f: |
|
|
|
|
csv_reader = csv.reader(f, delimiter=';') |
|
|
|
|
lines = 0 |
|
|
|
|
antwort_liste = [] |
|
|
|
|
for row in csv_reader: |
|
|
|
|
if lines == 0: |
|
|
|
|
# print(f'Column names are {", ".join(row)}') |
|
|
|
|
lines += 1 |
|
|
|
|
else: |
|
|
|
|
if isinstance(row, list): |
|
|
|
|
antwort_liste.extend(row) |
|
|
|
|
except FileNotFoundError: |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
@ -119,8 +128,9 @@ muell_arten = [
|
|
|
|
|
'Schadstoffmobil', |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
# __main__ |
|
|
|
|
if __name__ == '__main__': |
|
|
|
|
antwort_liste = read_file(current_year) |
|
|
|
|
|
|
|
|
|
if antwort_liste == None: |
|
|
|
|
# Keine vernünftigen Daten, ergo mal gucken, was die Webseite ergibt |
|
|
|
|
config = readConfig() |
|
|
|
@ -138,12 +148,12 @@ if antwort_liste == None:
|
|
|
|
|
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 = read_file(current_year) |
|
|
|
|
|
|
|
|
|
daten = set(antwort_liste) |
|
|
|
|
|
|
|
|
|
for datum in daten: |
|
|
|
|
# TODO: Leider weiss ich ab hier nur, dass Müll abgeholt wird, leider nicht, welcher :-/ |
|
|
|
|
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y') |
|
|
|
|
for datum in daten: |
|
|
|
|
datum = datum.split(';') |
|
|
|
|
l_muell = get_index_positions(datum, tomorrow) |
|
|
|
|
if len(l_muell) > 0: |
|
|
|
|