Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9701df6f39 | ||
|
|
3458b4e227 | ||
|
|
a964b2b5bc
|
||
|
|
d6cc9b974f
|
||
|
|
091e801b7e
|
||
|
|
8e6549fd5e
|
+38
-37
@@ -23,8 +23,6 @@ import csv
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
import httplib2
|
||||
import urllib
|
||||
import yaml
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
@@ -32,19 +30,21 @@ from pathlib import Path
|
||||
|
||||
class Muell:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
# Variablen
|
||||
__key = 'e21758b9c711463552fb9c70ac7d4273'
|
||||
__modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
|
||||
self.__key = 'e21758b9c711463552fb9c70ac7d4273'
|
||||
self.__modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
|
||||
|
||||
__host = 'api.abfall.io'
|
||||
self.__host = 'api.abfall.io'
|
||||
|
||||
__url = f'https://{__host}/?key={__key}&modus={__modus}&waction=export_csv'
|
||||
__export_als = f"{{'action':'{__url}','target':''}}"
|
||||
self.__url = f'https://{self.__host}/?key={self.__key}&modus={self.__modus}'
|
||||
self.__export_als = f"{{'action':'{self.__url}&waction=export_csv','target':''}}"
|
||||
|
||||
__current_year = datetime.today().year
|
||||
__zeitraum = f'{__current_year}0101-{__current_year}1231'
|
||||
self.__current_year = datetime.today().year
|
||||
self.__zeitraum = f'{self.__current_year}0101-{self.__current_year}1231'
|
||||
|
||||
__postdata = {
|
||||
self.__postdata = {
|
||||
'f_id_abfalltyp_0': '50',
|
||||
'f_id_abfalltyp_1': '161',
|
||||
'f_id_abfalltyp_2': '53',
|
||||
@@ -52,11 +52,11 @@ class Muell:
|
||||
'f_id_abfalltyp_4': '169',
|
||||
'f_abfallarten_index_max': '5',
|
||||
'f_abfallarten': '50,161,53,187',
|
||||
'f_zeitraum': __zeitraum,
|
||||
'f_export_als': __export_als,
|
||||
'f_zeitraum': self.__zeitraum,
|
||||
'f_export_als': self.__export_als,
|
||||
}
|
||||
|
||||
__headers = {
|
||||
self.__headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; x68_64; x64; rv:88.0) Gecko/20100101 Firefox/88.0',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
}
|
||||
@@ -82,12 +82,12 @@ class Muell:
|
||||
|
||||
return config
|
||||
|
||||
def __init(self, key, modus, host, headers):
|
||||
def __start(self):
|
||||
''' Initialisiert das System und sucht entsprechende Daten heraus '''
|
||||
|
||||
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(self.__postdata))
|
||||
url = f'{self.__url}&waction=init'
|
||||
resp = requests.post(url, data = self.__postdata, headers = self.__headers)
|
||||
content = resp.content
|
||||
|
||||
result = re.findall(r"<input .*?name=.*? value=.*?/>", str(content))
|
||||
|
||||
@@ -136,12 +136,13 @@ class Muell:
|
||||
self.__postdata['f_id_kommune'] = config['kommune']
|
||||
self.__postdata['f_id_strasse'] = config['strasse']
|
||||
|
||||
(name, value) = self.__init(key, modus, host, headers)
|
||||
(name, value) = self.__start()
|
||||
if name != None and value != None:
|
||||
self.__postdata[name] = value
|
||||
|
||||
http = httplib2.Http()
|
||||
(resp, content) = http.request(url, "POST", headers = headers, body = urllib.parse.urlencode(self.__postdata))
|
||||
url = f'{self.__url}&waction=export_csv'
|
||||
resp = requests.post(url, data = self.__postdata, headers = self.__headers)
|
||||
content = resp.content
|
||||
|
||||
antwort = str(content)
|
||||
f = open(f'muell{self.__current_year}.csv', 'wb')
|
||||
@@ -169,36 +170,36 @@ class Muell:
|
||||
for pos in index:
|
||||
tonnen.append(headline[pos])
|
||||
|
||||
return (tonnen, wird)
|
||||
|
||||
def ausgabe_telegram(self, tonnen, wird):
|
||||
''' Ausgabe Richtung Telegram'''
|
||||
|
||||
if len(tonnen) > 0:
|
||||
tonnen = ' und '.join(tonnen)
|
||||
ausgabe = f'Morgen {wird} {tonnen} abgeholt'
|
||||
else:
|
||||
ausgabe = None
|
||||
|
||||
return ausgabe
|
||||
|
||||
def ausgabe_telegram(self, ausgabe):
|
||||
''' Ausgabe Richtung Telegram'''
|
||||
|
||||
if ausgabe is not None:
|
||||
# Jetzt den Telegram Bot ansprechen
|
||||
try:
|
||||
os.system(f'echo "Morgen {wird} {tonnen} abgeholt" | {config["telegram"]["pathBot"]} -u {config["telegram"]["tgReceiver"]}')
|
||||
os.system(f'echo "{ausgabe}" | {config["telegram"]["pathBot"]} -u {config["telegram"]["tgReceiver"]}')
|
||||
except Exception as e:
|
||||
os.system(f'logger "Fehler Muellbot Telegram: {e}"')
|
||||
|
||||
def ausgabe_signal(self, tonnen, wird):
|
||||
def ausgabe_signal(self, ausgabe):
|
||||
''' Ausgabe Richtung Signal'''
|
||||
|
||||
if len(tonnen) > 0:
|
||||
|
||||
tonnen = ' und '.join(tonnen)
|
||||
|
||||
if ausgabe is not None:
|
||||
# Signal Bot
|
||||
try:
|
||||
os.system(f'{config["signal"]["path"]} -a {config["signal"]["account"]} send -g {config["signal"]["group_id"]} -m "Morgen {wird} {tonnen} abgeholt"')
|
||||
os.system(f'{config["signal"]["path"]} -a {config["signal"]["account"]} send -g {config["signal"]["group_id"]} -m "{ausgabe}"')
|
||||
except Exception as e:
|
||||
os.system(f'logger "Fehler Muellbot Signal: {e}"')
|
||||
|
||||
def ausgabe_text(self, tonnen, wird):
|
||||
def ausgabe_text(self, ausgabe):
|
||||
''' Ausgabe als Text'''
|
||||
|
||||
if len(tonnen) > 0:
|
||||
tonnen = ' und '.join(tonnen)
|
||||
|
||||
print(f'Morgen {wird} {tonnen} abgeholt')
|
||||
if ausgabe is not None:
|
||||
print(f'{ausgabe}')
|
||||
|
||||
+3
-3
@@ -4,6 +4,6 @@ from Muell import Muell
|
||||
|
||||
if __name__ == '__main__':
|
||||
muell = Muell()
|
||||
tonnen, wird = muell.get_data()
|
||||
muell.ausgabe_telegram(tonnen, wird)
|
||||
muell.ausgabe_signal(tonnen, wird)
|
||||
ausgabe = muell.get_data()
|
||||
muell.ausgabe_telegram(ausgabe)
|
||||
muell.ausgabe_signal(ausgabe)
|
||||
|
||||
Reference in New Issue
Block a user