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

removing debug file from aha_region_de + Reformatting #1318

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
@@ -1,8 +1,7 @@
from waste_collection_schedule import Collection # type: ignore[attr-defined]
from waste_collection_schedule.service.ICS import ICS

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

TITLE = "Zweckverband Abfallwirtschaft Region Hannover"
DESCRIPTION = "Source for Zweckverband Abfallwirtschaft Region Hannover."
Expand All @@ -14,9 +13,9 @@
"hnr": 1,
},
"Isernhagen, Am Lohner Hof / Isernhagen Fb, 10": {
"gemeinde": "Isernhagen",
"strasse": "Am Lohner Hof / Isernhagen Fb",
"hnr": "10",
"gemeinde": "Isernhagen",
"strasse": "Am Lohner Hof / Isernhagen Fb",
"hnr": "10",
},
"Hannover, Voltastr. / Vahrenwald, 25": {
"gemeinde": "Hannover",
Expand All @@ -28,7 +27,7 @@
"strasse": "Melanchthonstr.",
"hnr": "10",
"zusatz": "A",
}
},
}

ICON_MAP = {
Expand All @@ -41,8 +40,11 @@

API_URL = "https://www.aha-region.de/abholtermine/abfuhrkalender"


class Source:
def __init__(self, gemeinde: str, strasse: str, hnr: str | int, zusatz: str | int = ""):
def __init__(
self, gemeinde: str, strasse: str, hnr: str | int, zusatz: str | int = ""
):
self._gemeinde: str = gemeinde
self._strasse: str = strasse
self._hnr: str = str(hnr)
Expand All @@ -51,18 +53,31 @@ def __init__(self, gemeinde: str, strasse: str, hnr: str | int, zusatz: str | in

def fetch(self):
# find strassen_id
r = requests.get(API_URL, params={"gemeinde": self._gemeinde, "von": "A", "bis": "["})
r = requests.get(
API_URL, params={"gemeinde": self._gemeinde, "von": "A", "bis": "["}
)
r.raise_for_status()

strassen_id = None
selects = BeautifulSoup(r.text, "html.parser").find("select", {"id": "strasse"}).find_all("option")
selects = (
BeautifulSoup(r.text, "html.parser")
.find("select", {"id": "strasse"})
.find_all("option")
)
for select in selects:
if select.text.lower().replace(" ", "") == self._strasse.lower().replace(" ", ""):
if select.text.lower().replace(" ", "") == self._strasse.lower().replace(
" ", ""
):
strassen_id = select["value"]
break

if not strassen_id:
raise Exception("Street not found for gemeinde: " + self._gemeinde + " and strasse: " + self._strasse)
raise Exception(
"Street not found for gemeinde: "
+ self._gemeinde
+ " and strasse: "
+ self._strasse
)

# request overview page
args = {
Expand All @@ -82,9 +97,9 @@ def fetch(self):
download_buttons = soup.find_all("button", {"name": "ical_apple"})

if not download_buttons:
with open("/home/silas/tmp/test.html", "w") as f:
f.write(r.text)
raise Exception("Invalid response from server, check you configuration if it is correct.")
raise Exception(
"Invalid response from server, check you configuration if it is correct."
)

entries = []

Expand Down