|
1 |
| -import json |
2 |
| -import requests |
3 | 1 | import datetime
|
| 2 | +import json |
4 | 3 |
|
| 4 | +import requests |
5 | 5 | from bs4 import BeautifulSoup
|
6 | 6 | from waste_collection_schedule import Collection
|
7 | 7 |
|
|
10 | 10 | URL = "https://www.fkf.hu"
|
11 | 11 | COUNTRY = "hu"
|
12 | 12 | TEST_CASES = {
|
13 |
| - "Test_1": {"street": "Templom tér"}, |
14 |
| - "Test_2": {"street": "Völgy utca"}, |
15 |
| - "Test_3": {"street": "Zombori utca"} |
| 13 | + "Test_1": {"street": "Templom tér", "ssl_verify": False}, |
| 14 | + "Test_2": {"street": "Völgy utca", "ssl_verify": False}, |
| 15 | + "Test_3": {"street": "Zombori utca", "ssl_verify": False}, |
16 | 16 | }
|
17 | 17 |
|
18 |
| -API_URL = "https://www.fkf.hu/hulladeknaptar-budaors" |
| 18 | +API_URL = "https://www.mohubudapest.hu/hulladeknaptar-budaors" |
19 | 19 | ICON_MAP = {
|
20 | 20 | "COMMUNAL": "mdi:trash-can",
|
21 | 21 | "SELECTIVE": "mdi:recycle",
|
|
24 | 24 |
|
25 | 25 |
|
26 | 26 | class Source:
|
27 |
| - def __init__(self, street): |
| 27 | + def __init__(self, street, ssl_verify: bool = True): |
28 | 28 | self._street = street
|
| 29 | + self._ssl_verify = ssl_verify |
29 | 30 |
|
30 | 31 | def fetch(self):
|
31 | 32 | session = requests.Session()
|
32 | 33 |
|
33 | 34 | r = session.post(
|
34 | 35 | API_URL,
|
35 |
| - data={ |
36 |
| - "publicPlace": self._street |
37 |
| - }, |
| 36 | + data={"publicPlace": self._street}, |
38 | 37 | headers={
|
39 | 38 | "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
|
40 | 39 | "X-October-Request-Handler": "onSearch",
|
41 | 40 | "X-October-Request-Partials": "ajax/budaorsResults",
|
42 | 41 | "X-Requested-With": "XMLHttpRequest",
|
43 |
| - } |
| 42 | + }, |
| 43 | + verify=self._ssl_verify, |
44 | 44 | )
|
45 | 45 | r.raise_for_status()
|
46 |
| - soup = BeautifulSoup(json.loads(r.text)["ajax/budaorsResults"], features="html.parser") |
| 46 | + soup = BeautifulSoup( |
| 47 | + json.loads(r.text)["ajax/budaorsResults"], features="html.parser" |
| 48 | + ) |
47 | 49 |
|
48 |
| - if soup.find("div", attrs={"class":"alert"}) is not None: |
| 50 | + if soup.find("div", attrs={"class": "alert"}) is not None: |
49 | 51 | raise Exception("Address not found")
|
50 | 52 |
|
51 | 53 | entries = []
|
52 |
| - communal_divs = soup.find_all("div", attrs={"class":"communal"}) |
| 54 | + communal_divs = soup.find_all("div", attrs={"class": "communal"}) |
53 | 55 |
|
54 |
| - selective = soup.find_all("div", attrs={"class":"selective"}) |
55 |
| - communal = [i for i in filter(lambda div:div.text=="Kommunális", communal_divs)] |
56 |
| - green = [i for i in filter(lambda div:div.text=="Zöld", communal_divs)] |
| 56 | + selective = soup.find_all("div", attrs={"class": "selective"}) |
| 57 | + communal = [ |
| 58 | + i for i in filter(lambda div: div.text == "Kommunális", communal_divs) |
| 59 | + ] |
| 60 | + green = [i for i in filter(lambda div: div.text == "Zöld", communal_divs)] |
57 | 61 |
|
58 | 62 | for element in communal:
|
59 | 63 | entries.append(
|
60 | 64 | Collection(
|
61 |
| - date = datetime.datetime.strptime(element.parent.parent.findAll("td")[1].text, "%Y.%m.%d").date(), |
62 |
| - t = "Communal", |
63 |
| - icon = ICON_MAP.get("COMMUNAL"), |
| 65 | + date=datetime.datetime.strptime( |
| 66 | + element.parent.parent.findAll("td")[1].text, "%Y.%m.%d" |
| 67 | + ).date(), |
| 68 | + t="Communal", |
| 69 | + icon=ICON_MAP.get("COMMUNAL"), |
64 | 70 | )
|
65 | 71 | )
|
66 | 72 |
|
67 | 73 | for element in selective:
|
68 | 74 | entries.append(
|
69 | 75 | Collection(
|
70 |
| - date = datetime.datetime.strptime(element.parent.parent.findAll("td")[1].text, "%Y.%m.%d").date(), |
71 |
| - t = "Selective", |
72 |
| - icon = ICON_MAP.get("SELECTIVE"), |
| 76 | + date=datetime.datetime.strptime( |
| 77 | + element.parent.parent.findAll("td")[1].text, "%Y.%m.%d" |
| 78 | + ).date(), |
| 79 | + t="Selective", |
| 80 | + icon=ICON_MAP.get("SELECTIVE"), |
73 | 81 | )
|
74 | 82 | )
|
75 | 83 |
|
76 | 84 | for element in green:
|
77 | 85 | entries.append(
|
78 | 86 | Collection(
|
79 |
| - date = datetime.datetime.strptime(element.parent.parent.findAll("td")[1].text, "%Y.%m.%d").date(), |
80 |
| - t = "Green", |
81 |
| - icon = ICON_MAP.get("GREEN"), |
| 87 | + date=datetime.datetime.strptime( |
| 88 | + element.parent.parent.findAll("td")[1].text, "%Y.%m.%d" |
| 89 | + ).date(), |
| 90 | + t="Green", |
| 91 | + icon=ICON_MAP.get("GREEN"), |
82 | 92 | )
|
83 | 93 | )
|
84 | 94 |
|
|
0 commit comments