Private Eigenschaften in Klasse Muell

This commit is contained in:
Hauke Zühl 2026-05-23 09:36:49 +02:00
parent d6cc9b974f
commit a964b2b5bc
Signed by: hauke
GPG Key ID: 7E70BF5E52D4CA72

View File

@ -32,34 +32,36 @@ from pathlib import Path
class Muell:
# Variablen
key = 'e21758b9c711463552fb9c70ac7d4273'
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
def __init__(self):
host = 'api.abfall.io'
# Variablen
self.__key = 'e21758b9c711463552fb9c70ac7d4273'
self.__modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
url = f'https://{host}/?key={key}&modus={modus}&waction=export_csv'
export_als = f"{{'action':'{url}','target':''}}"
self.__host = 'api.abfall.io'
current_year = datetime.today().year
zeitraum = f'{current_year}0101-{current_year}1231'
self.__url = f'https://{self.__host}/?key={self.__key}&modus={self.__modus}&waction=export_csv'
self.__export_als = f"{{'action':'{self.__url}','target':''}}"
postdata = {
'f_id_abfalltyp_0': '50',
'f_id_abfalltyp_1': '161',
'f_id_abfalltyp_2': '53',
'f_id_abfalltyp_3': '187',
'f_id_abfalltyp_4': '169',
'f_abfallarten_index_max': '5',
'f_abfallarten': '50,161,53,187',
'f_zeitraum': zeitraum,
'f_export_als': export_als,
}
self.__current_year = datetime.today().year
self.__zeitraum = f'{self.__current_year}0101-{self.__current_year}1231'
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',
}
self.__postdata = {
'f_id_abfalltyp_0': '50',
'f_id_abfalltyp_1': '161',
'f_id_abfalltyp_2': '53',
'f_id_abfalltyp_3': '187',
'f_id_abfalltyp_4': '169',
'f_abfallarten_index_max': '5',
'f_abfallarten': '50,161,53,187',
'f_zeitraum': self.__zeitraum,
'f_export_als': self.__export_als,
}
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',
}
# Methoden
def __get_index_positions(self, list_of_elems, element):
@ -82,12 +84,12 @@ class Muell:
return config
def __init(self):
def __start(self):
''' Initialisiert das System und sucht entsprechende Daten heraus '''
url = f'https://{self.host}/?key={self.key}&modus={self.modus}&waction=init'
url = f'https://{self.__host}/?key={self.__key}&modus={self.__modus}&waction=init'
http = httplib2.Http()
(resp, content) = http.request(url, "POST", headers = self.headers, body = urllib.parse.urlencode(self.postdata))
(resp, content) = http.request(url, "POST", headers = self.__headers, body = urllib.parse.urlencode(self.__postdata))
result = re.findall(r"<input .*?name=.*? value=.*?/>", str(content))
@ -128,7 +130,7 @@ class Muell:
return (antwort_liste, headline)
def get_data(self):
(antwort_liste, headline) = self.__read_file(self.current_year)
(antwort_liste, headline) = self.__read_file(self.__current_year)
config = self.__readConfig()
if not antwort_liste:
@ -136,18 +138,18 @@ class Muell:
self.postdata['f_id_kommune'] = config['kommune']
self.postdata['f_id_strasse'] = config['strasse']
(name, value) = self.__init()
(name, value) = self.__start()
if name != None and value != None:
self.postdata[name] = value
http = httplib2.Http()
(resp, content) = http.request(self.url, "POST", headers = self.headers, body = urllib.parse.urlencode(self.postdata))
(resp, content) = http.request(self.__url, "POST", headers = self.__headers, body = urllib.parse.urlencode(self.__postdata))
antwort = str(content)
f = open(f'muell{self.current_year}.csv', 'wb')
f = open(f'muell{self._current_year}.csv', 'wb')
f.write(content)
f.close()
(antwort_liste, headline) = self.__read_file(self.current_year)
(antwort_liste, headline) = self.__read_file(self.__current_year)
tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
index = set();
@ -202,4 +204,3 @@ class Muell:
if ausgabe is not None:
print(f'{ausgabe}')