uk_bin_collection 0.141.4__py3-none-any.whl → 0.142.0__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.
@@ -1861,6 +1861,15 @@
1861
1861
  "wiki_name": "Stevenage Borough Council",
1862
1862
  "wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
1863
1863
  },
1864
+ "StirlingCouncil": {
1865
+ "url": "https://www.stirling.gov.uk/bins-and-recycling/bin-collection-dates-search/",
1866
+ "house_number": "5, SUNNYLAW ROAD, BRIDGE OF ALLAN, STIRLING, FK9 4QA",
1867
+ "postcode": "FK9 4QA",
1868
+ "skip_get_url": true,
1869
+ "web_driver": "http://selenium:4444",
1870
+ "wiki_name": "Stirling Council",
1871
+ "wiki_note": "Use the full address as it appears on the drop-down on the site when you search by postcode."
1872
+ },
1864
1873
  "StockportBoroughCouncil": {
1865
1874
  "url": "https://myaccount.stockport.gov.uk/bin-collections/show/100011434401",
1866
1875
  "wiki_command_url_override": "https://myaccount.stockport.gov.uk/bin-collections/show/XXXXXXXX",
@@ -0,0 +1,163 @@
1
+ # This script pulls bin collection data from Stirling Council
2
+ # Example URL: https://www.stirling.gov.uk/bins-and-recycling/bin-collection-dates-search/
3
+ import time
4
+
5
+ from bs4 import BeautifulSoup
6
+ from dateutil.parser import parse
7
+ from selenium.common.exceptions import NoSuchElementException, TimeoutException
8
+ from selenium.webdriver.common.by import By
9
+ from selenium.webdriver.common.keys import Keys
10
+ from selenium.webdriver.support import expected_conditions as EC
11
+ from selenium.webdriver.support.ui import Select
12
+ from selenium.webdriver.support.wait import WebDriverWait
13
+
14
+ from uk_bin_collection.uk_bin_collection.common import *
15
+ from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
16
+
17
+
18
+ class CouncilClass(AbstractGetBinDataClass):
19
+
20
+ def parse_data(self, page: str, **kwargs) -> dict:
21
+ driver = None
22
+ try:
23
+ data = {"bins": []}
24
+
25
+ user_paon = kwargs.get("paon")
26
+ postcode = kwargs.get("postcode")
27
+ web_driver = kwargs.get("web_driver")
28
+ headless = kwargs.get("headless")
29
+ url = kwargs.get("url")
30
+
31
+ print(
32
+ f"Starting parse_data with parameters: postcode={postcode}, paon={user_paon}"
33
+ )
34
+ print(
35
+ f"Creating webdriver with: web_driver={web_driver}, headless={headless}"
36
+ )
37
+
38
+ driver = create_webdriver(web_driver, headless, None, __name__)
39
+ print(f"Navigating to URL: {url}")
40
+ driver.get(url)
41
+ print("Successfully loaded the page")
42
+
43
+ # Handle cookie confirmation dialog
44
+ wait = WebDriverWait(driver, 60)
45
+
46
+ # Handle cookie banner if present
47
+ try:
48
+ cookie_button = wait.until(
49
+ EC.element_to_be_clickable((By.ID, "ccc-recommended-settings")),
50
+ message="Cookie banner not found",
51
+ )
52
+ cookie_button.click()
53
+ print("Cookie banner clicked.")
54
+ time.sleep(1) # Brief pause to let banner disappear
55
+ except (TimeoutException, NoSuchElementException):
56
+ print("No cookie banner appeared or selector failed.")
57
+
58
+ # Enter postcode
59
+ print("Looking for postcode input...")
60
+ post_code_input = wait.until(
61
+ EC.element_to_be_clickable((By.ID, "js-postcode-lookup-postcode")),
62
+ message="Postcode input not found",
63
+ )
64
+ post_code_input.clear()
65
+ post_code_input.send_keys(postcode)
66
+ print(f"Entered postcode: {postcode}")
67
+
68
+ driver.switch_to.active_element.send_keys(Keys.TAB + Keys.ENTER)
69
+ print("Pressed ENTER on Find")
70
+
71
+ # Wait for and select address
72
+ print("Waiting for address dropdown...")
73
+ address_select = wait.until(
74
+ EC.element_to_be_clickable((By.CLASS_NAME, "select__input")),
75
+ message="Address dropdown not found",
76
+ )
77
+ dropdown = Select(address_select)
78
+
79
+ dropdown.select_by_visible_text(user_paon)
80
+ print("Address selected successfully")
81
+
82
+ driver.switch_to.active_element.send_keys(Keys.TAB * 2 + Keys.ENTER)
83
+ print("Pressed ENTER on Next button")
84
+
85
+ print("Looking for schedule list...")
86
+ schedule_list = WebDriverWait(driver, 10).until(
87
+ EC.presence_of_element_located((By.CLASS_NAME, "schedule__list"))
88
+ )
89
+
90
+ # Make a BS4 object
91
+ print("Parsing page with BeautifulSoup...")
92
+ soup = BeautifulSoup(driver.page_source, features="html.parser")
93
+
94
+ # Process collection details
95
+ print("Looking for collection details in the page...")
96
+
97
+ schedule_items = []
98
+ selectors = [
99
+ "li.schedule__item",
100
+ ]
101
+
102
+ for selector in selectors:
103
+ items = soup.select(selector)
104
+ if items:
105
+ print(f"Found {len(items)} items using selector: {selector}")
106
+ schedule_items = items
107
+ break
108
+
109
+ print(f"\nProcessing {len(schedule_items)} schedule items...")
110
+
111
+ for item in schedule_items:
112
+ try:
113
+ # Try multiple selectors for bin type
114
+ title = item.find("h2", class_="schedule__title")
115
+
116
+ bin_type = title.text.strip()
117
+
118
+ summary = item.find("p", class_="schedule__summary")
119
+
120
+ # Extract date text
121
+ summary_text = summary.get_text(strip=True)
122
+ print(f"Found summary text: {summary_text}")
123
+
124
+ # Try different date formats
125
+ date_text = None
126
+ for splitter in ["Then every", "then every", "Every"]:
127
+ if splitter in summary_text:
128
+ date_text = summary_text.split(splitter)[0].strip()
129
+ break
130
+
131
+ if not date_text:
132
+ date_text = summary_text # Use full text if no splitter found
133
+
134
+ print(f"Extracted date text: {date_text}")
135
+
136
+ # Parse the date
137
+ cleaned_date_text = remove_ordinal_indicator_from_date_string(
138
+ date_text
139
+ )
140
+ parsed_date = parse(cleaned_date_text, fuzzy=True)
141
+ bin_date = parsed_date.strftime("%d/%m/%Y")
142
+
143
+ # Add only the next collection
144
+ if bin_type and bin_date:
145
+ dict_data = {
146
+ "type": bin_type,
147
+ "collectionDate": bin_date,
148
+ }
149
+ data["bins"].append(dict_data)
150
+ print(f"Successfully added collection: {dict_data}")
151
+
152
+ except Exception as e:
153
+ print(f"Error processing item: {e}")
154
+ continue
155
+ except Exception as e:
156
+ print(f"An error occurred: {e}")
157
+ raise
158
+ finally:
159
+ print("Cleaning up webdriver...")
160
+ if driver:
161
+ driver.quit()
162
+
163
+ return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.141.4
3
+ Version: 0.142.0
4
4
  Summary: Python Lib to collect UK Bin Data
5
5
  Author: Robert Bradley
6
6
  Author-email: robbrad182@gmail.com
@@ -3,7 +3,7 @@ uk_bin_collection/tests/check_selenium_url_in_input.json.py,sha256=Iecdja0I3XIiY
3
3
  uk_bin_collection/tests/council_feature_input_parity.py,sha256=DO6Mk4ImYgM5ZCZ-cutwz5RoYYWZRLYx2tr6zIs_9Rc,3843
4
4
  uk_bin_collection/tests/features/environment.py,sha256=VQZjJdJI_kZn08M0j5cUgvKT4k3iTw8icJge1DGOkoA,127
5
5
  uk_bin_collection/tests/features/validate_council_outputs.feature,sha256=SJK-Vc737hrf03tssxxbeg_JIvAH-ddB8f6gU1LTbuQ,251
6
- uk_bin_collection/tests/input.json,sha256=NQy_rR9oaERmyOMOwk02BTJqAafV1F-Nk1aNjJFTRag,120526
6
+ uk_bin_collection/tests/input.json,sha256=CheFZpYR_5AaYma_Eb1EtziWGQWR8c7nYgwLLzxAio4,120996
7
7
  uk_bin_collection/tests/output.schema,sha256=ZwKQBwYyTDEM4G2hJwfLUVM-5v1vKRvRK9W9SS1sd18,1086
8
8
  uk_bin_collection/tests/step_defs/step_helpers/file_handler.py,sha256=Ygzi4V0S1MIHqbdstUlIqtRIwnynvhu4UtpweJ6-5N8,1474
9
9
  uk_bin_collection/tests/step_defs/test_validate_council.py,sha256=VZ0a81sioJULD7syAYHjvK_-nT_Rd36tUyzPetSA0gk,3475
@@ -265,6 +265,7 @@ uk_bin_collection/uk_bin_collection/councils/StHelensBC.py,sha256=X9dvnQTNn7QUO8
265
265
  uk_bin_collection/uk_bin_collection/councils/StaffordBoroughCouncil.py,sha256=9Qj4HJI7Dbiqb2mVSG2UtkBe27Y7wvQ5SYFTwGzJ5g0,2292
266
266
  uk_bin_collection/uk_bin_collection/councils/StaffordshireMoorlandsDistrictCouncil.py,sha256=vdSnDbiKLQIdvvqVXDi2butZXRBMxv401aIrkLkKgy4,4370
267
267
  uk_bin_collection/uk_bin_collection/councils/StevenageBoroughCouncil.py,sha256=EiDIyOlHhdiJ-YYjo7T5uA5sN2jzNoysu6FctjuAjBI,3549
268
+ uk_bin_collection/uk_bin_collection/councils/StirlingCouncil.py,sha256=QaUw5oP_mmFAXo98EdHhI6lWo4OjF2E8zY2M7HQo2bk,6308
268
269
  uk_bin_collection/uk_bin_collection/councils/StockportBoroughCouncil.py,sha256=v0HmioNVRoU1-9OnLJl2V3M5pVR1aVu1BgOLHFR1Sf4,1429
269
270
  uk_bin_collection/uk_bin_collection/councils/StocktonOnTeesCouncil.py,sha256=obaBgsmIJ95Ah7KaTNWdU107tZDPVuuJox0mGUoGjNk,6070
270
271
  uk_bin_collection/uk_bin_collection/councils/StokeOnTrentCityCouncil.py,sha256=KM0EgWeO7mk8lkozX0RCTfMchXdjrfBqIjCiOtB09aM,2884
@@ -326,8 +327,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
326
327
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=EQWRhZ2pEejlvm0fPyOTsOHKvUZmPnxEYO_OWRGKTjs,1158
327
328
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
328
329
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
329
- uk_bin_collection-0.141.4.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
330
- uk_bin_collection-0.141.4.dist-info/METADATA,sha256=3InKR2PGDz8pWtSdL27kM0OwKZAZV0dxHHhZaK06LWs,19851
331
- uk_bin_collection-0.141.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
332
- uk_bin_collection-0.141.4.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
333
- uk_bin_collection-0.141.4.dist-info/RECORD,,
330
+ uk_bin_collection-0.142.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
331
+ uk_bin_collection-0.142.0.dist-info/METADATA,sha256=i2E_v_Kj_688lBYFandCTV20fc9CRU4UJIl50Z30AmU,19851
332
+ uk_bin_collection-0.142.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
333
+ uk_bin_collection-0.142.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
334
+ uk_bin_collection-0.142.0.dist-info/RECORD,,