Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWB Emsland request this AND next years data instead of only next years #3134

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from html.parser import HTMLParser

import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

Expand Down Expand Up @@ -74,7 +75,49 @@ def __init__(
self._suffix = address_suffix
self._ics = ICS()

def get_zeitraum_values(self):
try:
session = requests.session()

response = session.get(
SERVLET,
params={"SubmitAction": "wasteDisposalServices"},
)
response.raise_for_status()

# Parse the HTML content
soup = BeautifulSoup(response.text, "html.parser")

# Find all input elements with the name "Zeitraum"
input_elements = soup.find_all("input", {"name": "Zeitraum"})

# Extract values
values = [
input_elem.get("value")
for input_elem in input_elements
if input_elem.get("value")
]
return values

except requests.exceptions.RequestException:
return []

def fetch(self):
available_years = self.get_zeitraum_values()

if available_years:
values = []

for year in available_years:
result = self.fetch_year(year)
values.extend(result)

return values

else:
return self.fetch_year()

def fetch_year(self, year=None):
session = requests.session()

r = session.get(
Expand All @@ -93,6 +136,10 @@ def fetch(self):
args["Hausnummer"] = str(self._hnr)
args["Hausnummerzusatz"] = self._suffix
args["SubmitAction"] = "CITYCHANGED"

if year:
args["Zeitraum"] = year

r = session.post(
SERVLET,
data=args,
Expand Down
1 change: 1 addition & 0 deletions doc/source/awb_emsland_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ 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.awb-emsland.de/service/abfuhrkalender/>. Typos will result in an parsing error which is printed in the log. As `house_number` expects a numeric input, address suffixes have to be provided via the `address_suffix` argument.

`address_suffix` could be for example a alphanumeric character "A" or a additional house number like "/1".
Loading