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: class Muell:
# Variablen def __init__(self):
key = 'e21758b9c711463552fb9c70ac7d4273'
modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
host = 'api.abfall.io' # Variablen
self.__key = 'e21758b9c711463552fb9c70ac7d4273'
self.__modus = 'd6c5855a62cf32a4dadbc2831f0f295f'
url = f'https://{host}/?key={key}&modus={modus}&waction=export_csv' self.__host = 'api.abfall.io'
export_als = f"{{'action':'{url}','target':''}}"
current_year = datetime.today().year self.__url = f'https://{self.__host}/?key={self.__key}&modus={self.__modus}&waction=export_csv'
zeitraum = f'{current_year}0101-{current_year}1231' self.__export_als = f"{{'action':'{self.__url}','target':''}}"
postdata = { self.__current_year = datetime.today().year
'f_id_abfalltyp_0': '50', self.__zeitraum = f'{self.__current_year}0101-{self.__current_year}1231'
'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,
}
headers = { self.__postdata = {
'User-Agent': 'Mozilla/5.0 (Linux; x68_64; x64; rv:88.0) Gecko/20100101 Firefox/88.0', 'f_id_abfalltyp_0': '50',
'Content-Type': 'application/x-www-form-urlencoded', '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 # Methoden
def __get_index_positions(self, list_of_elems, element): def __get_index_positions(self, list_of_elems, element):
@ -82,12 +84,12 @@ class Muell:
return config return config
def __init(self): def __start(self):
''' Initialisiert das System und sucht entsprechende Daten heraus ''' ''' 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() 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)) result = re.findall(r"<input .*?name=.*? value=.*?/>", str(content))
@ -128,7 +130,7 @@ class Muell:
return (antwort_liste, headline) return (antwort_liste, headline)
def get_data(self): 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() config = self.__readConfig()
if not antwort_liste: if not antwort_liste:
@ -136,18 +138,18 @@ class Muell:
self.postdata['f_id_kommune'] = config['kommune'] self.postdata['f_id_kommune'] = config['kommune']
self.postdata['f_id_strasse'] = config['strasse'] self.postdata['f_id_strasse'] = config['strasse']
(name, value) = self.__init() (name, value) = self.__start()
if name != None and value != None: if name != None and value != None:
self.postdata[name] = value self.postdata[name] = value
http = httplib2.Http() 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) 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.write(content)
f.close() 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') tomorrow = (datetime.now() + timedelta(1)).strftime('%d.%m.%Y')
index = set(); index = set();
@ -202,4 +204,3 @@ class Muell:
if ausgabe is not None: if ausgabe is not None:
print(f'{ausgabe}') print(f'{ausgabe}')