Skip to content

Commit

Permalink
abfallwirtschaft_pforzheim_de get next year data
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Dec 30, 2023
1 parent 4be7178 commit 344ae4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from html.parser import HTMLParser

import requests
Expand Down Expand Up @@ -63,12 +64,21 @@ def __init__(self, street: str, house_number: int, address_suffix: str = ""):
self._ics = ICS()

def fetch(self):
now = datetime.now()
entries = self.get_data(now.year)
if now.month == 12:
try:
entries += self.get_data(now.year + 1)
except Exception:
pass
return entries

def get_data(self, year):
session = requests.session()

r = session.get(
API_URL,
params={"SubmitAction": "wasteDisposalServices",
"InFrameMode": "TRUE"},
params={"SubmitAction": "wasteDisposalServices", "InFrameMode": "TRUE"},
)
r.raise_for_status()
r.encoding = "utf-8"
Expand All @@ -82,6 +92,7 @@ def fetch(self):
args["Hausnummer"] = str(self._hnr)
args["Hausnummerzusatz"] = self._suffix
args["SubmitAction"] = "CITYCHANGED"
args["Zeitraum"] = f"Jahresübersicht {year}"
r = session.post(
API_URL,
data=args,
Expand Down Expand Up @@ -113,9 +124,5 @@ def fetch(self):

entries = []
for d in dates:
entries.append(
Collection(
d[0], d[1], ICON_MAP.get(d[1].split(" ")[0])
)
)
entries.append(Collection(d[0], d[1], ICON_MAP.get(d[1].split(" ")[0])))
return entries
2 changes: 1 addition & 1 deletion doc/source/abfallwirtschaft_pforzheim_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ waste_collection_schedule:
## How to get the source arguments
These values are the location you want to query for. Make sure, the writing is exactly as it is on [https://www.abfallwirtschaft-pforzheim.de/kundenportal/abfallkalender](https://www.abfallwirtschaft-pforzheim.de/kundenportal/abfallkalender). Typos may result in an Exception. As `house_number` expects a numeric input, address suffixes have to be provided via the `address_suffix` argument.
These values are the location you want to query for. Make sure, the writing is exactly as it is on [https://www.abfallwirtschaft-pforzheim.de/abfallkalender](https://www.abfallwirtschaft-pforzheim.de/abfallkalender). Typos may result in an Exception. As `house_number` expects a numeric input, address suffixes have to be provided via the `address_suffix` argument.

0 comments on commit 344ae4e

Please sign in to comment.