Skip to content

Commit

Permalink
reformatting eth_erd_hu (#1349)
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 22, 2023
1 parent 491a309 commit 13c5679
Showing 1 changed file with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
import json
import requests
import datetime
import json

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

TITLE = "ÉTH (Érd, Diósd, Nagytarcsa, Sóskút, Tárnok)"
DESCRIPTION = "Source script for www.eth-erd.hu"
URL = "https://www.eth-erd.hu"
COUNTRY = "hu"
TEST_CASES = {
"Test_1": {
"city": "Diósd",
"street": "Diófasor",
"house_number": 10
},
"Test_2": {
"city": "Érd",
"street": "Hordó",
"house_number": 3
},
"Test_3": {
"city": "Sóskút"
}
"Test_1": {"city": "Diósd", "street": "Diófasor", "house_number": 10},
"Test_2": {"city": "Érd", "street": "Hordó", "house_number": 3},
"Test_3": {"city": "Sóskút"},
}

API_URL = "https://www.eth-erd.hu/trashcalendarget"
Expand Down Expand Up @@ -64,39 +53,47 @@ def fetch(self):
session = requests.Session()

city_id = CITY_MAP.get(self._city.lower())
if city_id == None: raise Exception("City not found")
if city_id is None:
raise Exception("City not found")
has_streets = city_id != CITY_MAP["sóskút"]

if has_streets:
r = session.post(
API_URL + "streets",
data={
"sid": city_id
},
data={"sid": city_id},
headers={
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
}
},
)
r.raise_for_status()
streets = json.loads(r.text)["results"]
available_streets = [item["text"] for item in streets]
try: street_id = [item for item in streets if item.get('text') == self._street][0]["id"]
except IndexError: raise Exception("Street not found, available streets: " + ", ".join(available_streets))
try:
street_id = [
item for item in streets if item.get("text") == self._street
][0]["id"]
except IndexError:
raise Exception(
"Street not found, available streets: "
+ ", ".join(available_streets)
)

r = session.post(
API_URL,
data={
"wctown": city_id,
"wcstreet": street_id,
"wchousenumber": self._house_number,
} if has_streets else {
}
if has_streets
else {
"wctown": city_id,
},
headers={
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
}
},
)
r.raise_for_status()
result: dict = json.loads(r.text)
Expand All @@ -111,9 +108,9 @@ def fetch(self):
for element in result["routelist"][trash_type_id]:
entries.append(
Collection(
date = datetime.datetime.strptime(element, "%Y-%m-%d").date(),
t = trash_name,
icon = trash_icon,
date=datetime.datetime.strptime(element, "%Y-%m-%d").date(),
t=trash_name,
icon=trash_icon,
)
)

Expand Down

0 comments on commit 13c5679

Please sign in to comment.