Skip to content

Commit

Permalink
removing debug file from aha_region_de + Reformatting (#1318)
Browse files Browse the repository at this point in the history
Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
  • Loading branch information
5ila5 and 5ila5 authored Oct 12, 2023
1 parent 62552cc commit 085a71f
Showing 1 changed file with 30 additions and 15 deletions.
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

0 comments on commit 085a71f

Please sign in to comment.