uk_bin_collection 0.90.0__py3-none-any.whl → 0.91.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -341,6 +341,15 @@
341
341
  "wiki_name": "East Lindsey District Council",
342
342
  "wiki_note": "Pass the house name/number in the house number parameter, wrapped in double quotes"
343
343
  },
344
+ "EastRenfrewshireCouncil": {
345
+ "house_number": "23",
346
+ "postcode": "G46 6RG",
347
+ "skip_get_url": true,
348
+ "url": "https://eastrenfrewshire.gov.uk/",
349
+ "web_driver": "http://selenium:4444",
350
+ "wiki_name": "East Renfrewshire Council",
351
+ "wiki_note": "Pass the house name/number in the house number parameter, wrapped in double quotes"
352
+ },
344
353
  "EastRidingCouncil": {
345
354
  "house_number": "14 THE LEASES BEVERLEY HU17 8LG",
346
355
  "postcode": "HU17 8LG",
@@ -1,4 +1,5 @@
1
1
  from bs4 import BeautifulSoup, element
2
+
2
3
  from uk_bin_collection.uk_bin_collection.common import *
3
4
  from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
4
5
 
@@ -13,7 +14,6 @@ class CouncilClass(AbstractGetBinDataClass):
13
14
 
14
15
  def parse_data(self, page: str, **kwargs) -> dict:
15
16
  data = {"bins": []}
16
- collections = []
17
17
  url_base = "https://geoapi.dorsetcouncil.gov.uk/v1/services/"
18
18
  url_types = ["recyclingday", "refuseday", "foodwasteday", "gardenwasteday"]
19
19
 
@@ -25,18 +25,17 @@ class CouncilClass(AbstractGetBinDataClass):
25
25
  response = requests.get(f"{url_base}{url_type}/{uprn}")
26
26
  if response.status_code != 200:
27
27
  raise ConnectionError(f"Could not fetch from {url_type} endpoint")
28
- json_data = response.json()["values"][0]
29
- collections.append((f"{json_data.get('type')} bin", datetime.strptime(json_data.get('dateNextVisit'), "%Y-%m-%d")))
30
-
31
- # Sort the text and date elements by date
32
- ordered_data = sorted(collections, key=lambda x: x[1])
33
-
34
- # Put the elements into the dictionary
35
- for item in ordered_data:
36
- dict_data = {
37
- "type": item[0],
38
- "collectionDate": item[1].strftime(date_format),
39
- }
40
- data["bins"].append(dict_data)
28
+ if response.json()["values"]:
29
+ json_data = response.json()["values"][0]
30
+
31
+ next_collection_date = datetime.strptime(
32
+ json_data.get("dateNextVisit"), "%Y-%m-%d"
33
+ )
34
+
35
+ dict_data = {
36
+ "type": f"{json_data.get('type')} bin",
37
+ "collectionDate": next_collection_date.strftime("%d/%m/%Y"),
38
+ }
39
+ data["bins"].append(dict_data)
41
40
 
42
41
  return data
@@ -0,0 +1,117 @@
1
+ from bs4 import BeautifulSoup
2
+ from selenium.webdriver.common.by import By
3
+ from selenium.webdriver.support import expected_conditions as EC
4
+ from selenium.webdriver.support.wait import WebDriverWait
5
+
6
+ from uk_bin_collection.uk_bin_collection.common import *
7
+ from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
8
+
9
+
10
+ # import the wonderful Beautiful Soup and the URL grabber
11
+ class CouncilClass(AbstractGetBinDataClass):
12
+ """
13
+ Concrete classes have to implement all abstract operations of the
14
+ base class. They can also override some operations with a default
15
+ implementation.
16
+ """
17
+
18
+ def parse_data(self, page: str, **kwargs) -> dict:
19
+ driver = None
20
+ try:
21
+ data = {"bins": []}
22
+ user_paon = kwargs.get("paon")
23
+ user_postcode = kwargs.get("postcode")
24
+ web_driver = kwargs.get("web_driver")
25
+ headless = kwargs.get("headless")
26
+ check_paon(user_paon)
27
+ check_postcode(user_postcode)
28
+
29
+ # Create Selenium webdriver
30
+ driver = create_webdriver(web_driver, headless, None, __name__)
31
+ driver.get(
32
+ "https://eastrenfrewshire.gov.uk/article/1145/Bin-collection-days"
33
+ )
34
+
35
+ # Wait for the postcode field to appear then populate it
36
+ inputElement_postcode = WebDriverWait(driver, 30).until(
37
+ EC.presence_of_element_located(
38
+ (By.ID, "RESIDUALWASTEV2_PAGE1_POSTCODE")
39
+ )
40
+ )
41
+ inputElement_postcode.send_keys(user_postcode)
42
+
43
+ # Click search button
44
+ findAddress = WebDriverWait(driver, 10).until(
45
+ EC.presence_of_element_located(
46
+ (By.ID, "RESIDUALWASTEV2_PAGE1_FIELD199_NEXT")
47
+ )
48
+ )
49
+ findAddress.click()
50
+
51
+ # Wait for the 'Select address' dropdown to appear and select option matching the house name/number
52
+ WebDriverWait(driver, 10).until(
53
+ EC.element_to_be_clickable(
54
+ (
55
+ By.XPATH,
56
+ "//select[@id='RESIDUALWASTEV2_PAGE2_UPRN']//option[contains(., '"
57
+ + user_paon
58
+ + "')]",
59
+ )
60
+ )
61
+ ).click()
62
+
63
+ # Click search button
64
+ findDates = WebDriverWait(driver, 10).until(
65
+ EC.presence_of_element_located(
66
+ (By.ID, "RESIDUALWASTEV2_PAGE2_FIELD206_NEXT")
67
+ )
68
+ )
69
+ findDates.click()
70
+
71
+ # Wait for the collections table to appear
72
+ WebDriverWait(driver, 10).until(
73
+ EC.presence_of_element_located(
74
+ (By.ID, "RESIDUALWASTEV2_COLLECTIONDATES_DISPLAYBINCOLLECTIONINFO")
75
+ )
76
+ )
77
+
78
+ soup = BeautifulSoup(driver.page_source, features="html.parser")
79
+ soup.prettify()
80
+
81
+ # Get collections div
82
+ next_collection_div = soup.find("div", {"id": "yourNextCollection"})
83
+
84
+ # Get next collection date
85
+ next_collection_date = datetime.strptime(
86
+ next_collection_div.find("span", {"class": "dueDate"})
87
+ .get_text()
88
+ .strip(),
89
+ "%d/%m/%Y",
90
+ )
91
+
92
+ # Get next collection bins
93
+ next_collection_bin = next_collection_div.findAll(
94
+ "span", {"class": "binColour"}
95
+ )
96
+
97
+ # Format results
98
+ for row in next_collection_bin:
99
+ dict_data = {
100
+ "type": row.get_text().strip(),
101
+ "collectionDate": next_collection_date.strftime("%d/%m/%Y"),
102
+ }
103
+ data["bins"].append(dict_data)
104
+
105
+ data["bins"].sort(
106
+ key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
107
+ )
108
+ except Exception as e:
109
+ # Here you can log the exception if needed
110
+ print(f"An error occurred: {e}")
111
+ # Optionally, re-raise the exception if you want it to propagate
112
+ raise
113
+ finally:
114
+ # This block ensures that the driver is closed regardless of an exception
115
+ if driver:
116
+ driver.quit()
117
+ return data
@@ -32,10 +32,8 @@ class CouncilClass(AbstractGetBinDataClass):
32
32
  "https://www.gateshead.gov.uk/article/3150/Bin-collection-day-checker"
33
33
  )
34
34
 
35
- accept_button = WebDriverWait(driver, timeout=30).until(
36
- EC.element_to_be_clickable(
37
- (By.CLASS_NAME, "btn btn--contrast btn--complete")
38
- )
35
+ accept_button = WebDriverWait(driver, 30).until(
36
+ EC.presence_of_element_located((By.NAME, "acceptall"))
39
37
  )
40
38
  accept_button.click()
41
39
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.90.0
3
+ Version: 0.91.1
4
4
  Summary: Python Lib to collect UK Bin Data
5
5
  Author: Robert Bradley
6
6
  Author-email: robbrad182@gmail.com
@@ -2,7 +2,7 @@ uk_bin_collection/README.rst,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,
2
2
  uk_bin_collection/tests/council_feature_input_parity.py,sha256=DO6Mk4ImYgM5ZCZ-cutwz5RoYYWZRLYx2tr6zIs_9Rc,3843
3
3
  uk_bin_collection/tests/features/environment.py,sha256=VQZjJdJI_kZn08M0j5cUgvKT4k3iTw8icJge1DGOkoA,127
4
4
  uk_bin_collection/tests/features/validate_council_outputs.feature,sha256=SJK-Vc737hrf03tssxxbeg_JIvAH-ddB8f6gU1LTbuQ,251
5
- uk_bin_collection/tests/input.json,sha256=p6iViHOSYbTWhUp9ICC46nws0Wusa7akA5k5--vGQaI,60871
5
+ uk_bin_collection/tests/input.json,sha256=wvkZlpCUMF9dJl3nl0Uy1G8OwwInlIBr5s45YHa6HhY,61255
6
6
  uk_bin_collection/tests/output.schema,sha256=ZwKQBwYyTDEM4G2hJwfLUVM-5v1vKRvRK9W9SS1sd18,1086
7
7
  uk_bin_collection/tests/step_defs/step_helpers/file_handler.py,sha256=Ygzi4V0S1MIHqbdstUlIqtRIwnynvhu4UtpweJ6-5N8,1474
8
8
  uk_bin_collection/tests/step_defs/test_validate_council.py,sha256=LrOSt_loA1Mw3vTqaO2LpaDMu7rYJy6k5Kr-EOBln7s,3424
@@ -52,13 +52,14 @@ uk_bin_collection/uk_bin_collection/councils/CroydonCouncil.py,sha256=QJH27plySb
52
52
  uk_bin_collection/uk_bin_collection/councils/DartfordBoroughCouncil.py,sha256=SPirUUoweMwX5Txtsr0ocdcFtKxCQ9LhzTTJN20tM4w,1550
53
53
  uk_bin_collection/uk_bin_collection/councils/DerbyshireDalesDistrictCouncil.py,sha256=MQC1-jXezXczrxTcvPQvkpGgyyAbzSKlX38WsmftHak,4007
54
54
  uk_bin_collection/uk_bin_collection/councils/DoncasterCouncil.py,sha256=b7pxoToXu6dBBYXsXmlwfPXE8BjHxt0hjCOBNlNgvX8,3118
55
- uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py,sha256=zfXQJpywfEQvBOhv5uPSkHdTrAg114yXIuTYDjHSXsA,1629
55
+ uk_bin_collection/uk_bin_collection/councils/DorsetCouncil.py,sha256=XUWH5BzkjPSFBLczo-Vo-Wly2JMoabm9WtI6_Mf-pO4,1523
56
56
  uk_bin_collection/uk_bin_collection/councils/DoverDistrictCouncil.py,sha256=3Zgap6kaVpDXtRfBKEL1Ms6eb0iFIipYKNtOq3Hrdd4,1891
57
57
  uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py,sha256=6O8bNsQVYQbrCYQE9Rp0c_rtkcXuxR3s9J6jn4MK4_s,1695
58
58
  uk_bin_collection/uk_bin_collection/councils/EalingCouncil.py,sha256=UhNXGi-_6NYZu50988VEvOzmAVunxOoyJ6mz0OEaUz4,1321
59
59
  uk_bin_collection/uk_bin_collection/councils/EastCambridgeshireCouncil.py,sha256=aYUVE5QqTxdj8FHhCB4EiFVDJahWJD9Pq0d1upBEvXg,1501
60
60
  uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py,sha256=U0VwSNIldMv5nUoiXtFgjbE0m6Kb-8W2WZQGVCNF_WI,3261
61
61
  uk_bin_collection/uk_bin_collection/councils/EastLindseyDistrictCouncil.py,sha256=o_HPSFhb2ybmwv32_7T7CO1f2mGDkYCNPfaM5xz6bUI,4356
62
+ uk_bin_collection/uk_bin_collection/councils/EastRenfrewshireCouncil.py,sha256=5giegMCKQ2JhVDR5M4mevVxIdhZtSW7kbuuoSkj3EGk,4361
62
63
  uk_bin_collection/uk_bin_collection/councils/EastRidingCouncil.py,sha256=CsYdkmL-8Ty-Kz7uNdlnJnhiDMgOPah_swYgSKbaFqA,5218
63
64
  uk_bin_collection/uk_bin_collection/councils/EastSuffolkCouncil.py,sha256=qQ0oOfGd0sWcczse_B22YoeL9uj3og8v3UJLt_Sx29c,4353
64
65
  uk_bin_collection/uk_bin_collection/councils/EastleighBoroughCouncil.py,sha256=V4Vso4DvawFiezKlmXbTlJEK9Sjhz9nA8WeYjwtO2e4,2310
@@ -69,7 +70,7 @@ uk_bin_collection/uk_bin_collection/councils/ErewashBoroughCouncil.py,sha256=QTQ
69
70
  uk_bin_collection/uk_bin_collection/councils/FarehamBoroughCouncil.py,sha256=25QxeN5q3ad1Wwexs2d-B7ooH0ru6pOUx58413FOTY4,2352
70
71
  uk_bin_collection/uk_bin_collection/councils/FenlandDistrictCouncil.py,sha256=sFrnKzIE2tIcz0YrC6A9HcevzgNdf6E6_HLGMWDKtGw,2513
71
72
  uk_bin_collection/uk_bin_collection/councils/ForestOfDeanDistrictCouncil.py,sha256=xO5gqgsN9K-cQsuDoQF7ycZkjNdCPAQwIYOCFWxFJ_Y,4504
72
- uk_bin_collection/uk_bin_collection/councils/GatesheadCouncil.py,sha256=Ecq4kMbtAHnQrnxjhC7CG3oEZQ3D1aAk5qXVZk-ouxc,4601
73
+ uk_bin_collection/uk_bin_collection/councils/GatesheadCouncil.py,sha256=SRCgYhYs6rv_8C1UEDVORHZgXxcJkoZBjzdYS4Lu-ew,4531
73
74
  uk_bin_collection/uk_bin_collection/councils/GedlingBoroughCouncil.py,sha256=IssL5CJSdcGPkJCB0q2kieUSEjfoS6nDKfeT7-9eKsQ,2183
74
75
  uk_bin_collection/uk_bin_collection/councils/GlasgowCityCouncil.py,sha256=IOgM8Wl-LpO1T-F9uU1FlVfPaEObpvsdP7S2h03Mycc,2528
75
76
  uk_bin_collection/uk_bin_collection/councils/GloucesterCityCouncil.py,sha256=8Wjvmdvg5blHVrREaEnhhWZaWhYVP4v_KdDVPLIUxaU,4889
@@ -190,8 +191,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
190
191
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
191
192
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
192
193
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
193
- uk_bin_collection-0.90.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
194
- uk_bin_collection-0.90.0.dist-info/METADATA,sha256=vMK8B_LKC5lb-ruji0R6pvrzUG3IIxptlWWZT0fvEFo,16642
195
- uk_bin_collection-0.90.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
196
- uk_bin_collection-0.90.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
197
- uk_bin_collection-0.90.0.dist-info/RECORD,,
194
+ uk_bin_collection-0.91.1.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
195
+ uk_bin_collection-0.91.1.dist-info/METADATA,sha256=lc_NSdYQBqKFcC13H1v1XV2sTVRLLK2Tiqtg-WVwvew,16642
196
+ uk_bin_collection-0.91.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
197
+ uk_bin_collection-0.91.1.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
198
+ uk_bin_collection-0.91.1.dist-info/RECORD,,