uk_bin_collection 0.98.1__py3-none-any.whl → 0.98.3__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.
@@ -29,7 +29,7 @@ class CouncilClass(AbstractGetBinDataClass):
29
29
  headless = kwargs.get("headless")
30
30
 
31
31
  # Create Selenium webdriver
32
- page = f"https://www.eastriding.gov.uk/environment/bins-rubbish-recycling/bins-and-collections/bin-collection-dates/"
32
+ page = "https://www.eastriding.gov.uk/environment/bins-rubbish-recycling/bins-and-collections/bin-collection-dates/#"
33
33
 
34
34
  driver = create_webdriver(web_driver, headless, None, __name__)
35
35
  driver.get(page)
@@ -52,7 +52,7 @@ class CouncilClass(AbstractGetBinDataClass):
52
52
 
53
53
  expand_postcode_box = wait.until(
54
54
  EC.element_to_be_clickable(
55
- (By.ID, "when-and-where-should-i-put-my-bin-out")
55
+ (By.XPATH, '//a[contains(text(), "Open all")]')
56
56
  )
57
57
  )
58
58
 
@@ -7,28 +7,18 @@ from bs4 import BeautifulSoup
7
7
  from uk_bin_collection.uk_bin_collection.common import *
8
8
  from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
9
9
 
10
-
11
- # import the wonderful Beautiful Soup and the URL grabber
12
10
  class CouncilClass(AbstractGetBinDataClass):
13
- """
14
- Concrete classes have to implement all abstract operations of the
15
- base class. They can also override some operations with a default
16
- implementation.
17
- """
18
-
19
11
  def parse_data(self, page: str, **kwargs) -> dict:
20
12
 
21
13
  user_postcode = kwargs.get("postcode")
22
14
  check_postcode(user_postcode)
23
15
 
24
- root_url = "https://myproperty.molevalley.gov.uk/molevalley/api/live_addresses/{}?format=json".format(
25
- user_postcode
26
- )
27
- requests.packages.urllib3.disable_warnings()
16
+ # Fetch the page content
17
+ root_url = "https://myproperty.molevalley.gov.uk/molevalley/api/live_addresses/{}?format=json".format(user_postcode)
28
18
  response = requests.get(root_url, verify=False)
29
19
 
30
20
  if not response.ok:
31
- raise ValueError("Invalid server response code retreiving data.")
21
+ raise ValueError("Invalid server response code retrieving data.")
32
22
 
33
23
  jsonData = response.json()
34
24
 
@@ -37,7 +27,6 @@ class CouncilClass(AbstractGetBinDataClass):
37
27
 
38
28
  properties_found = jsonData["results"]["features"]
39
29
 
40
- # If UPRN is provided, we can check a specific address.
41
30
  html_data = None
42
31
  uprn = kwargs.get("uprn")
43
32
  if uprn:
@@ -49,53 +38,81 @@ class CouncilClass(AbstractGetBinDataClass):
49
38
  if html_data is None:
50
39
  raise ValueError("No collection data found for UPRN provided.")
51
40
  else:
52
- # If UPRN not provided, just use the first result
53
41
  html_data = properties_found[0]["properties"]["three_column_layout_html"]
54
42
 
55
- soup = BeautifulSoup(html_data, features="html.parser")
56
- soup.prettify()
43
+ # Conditionally replace the commented-out sections (<!-- ... -->)
44
+ if "<!--" in html_data and "-->" in html_data:
45
+ print("Commented-out section found, replacing comments...")
46
+ html_data = html_data.replace("<!--", "").replace("-->", "")
47
+ else:
48
+ print("No commented-out section found, processing as is.")
49
+
50
+ # Process the updated HTML data with BeautifulSoup
51
+ soup = BeautifulSoup(html_data, "html.parser")
57
52
 
58
53
  data = {"bins": []}
59
54
  all_collection_dates = []
60
- regex_date = re.compile(r".* ([\d]+\/[\d]+\/[\d]+)")
55
+ regex_date = re.compile(r"(\d{2}/\d{2}/\d{4})") # Adjusted date regex
61
56
  regex_additional_collection = re.compile(r"We also collect (.*) on (.*) -")
62
57
 
58
+ # Debugging to verify the HTML content is parsed correctly
59
+ print("HTML content parsed successfully.")
60
+
63
61
  # Search for the 'Bins and Recycling' panel
64
- for panel in soup.select('div[class*="panel"]'):
65
- if panel.h2.text.strip() == "Bins and Recycling":
66
-
67
- # Gather the bin types and dates
68
- for collection in panel.select("div > strong"):
69
- bin_type = collection.text.strip()
70
- collection_string = collection.find_next("p").text.strip()
71
- m = regex_date.match(collection_string)
72
- if m:
73
- collection_date = datetime.strptime(
74
- m.group(1), "%d/%m/%Y"
75
- ).date()
76
- data["bins"].append(
77
- {
62
+ bins_panel = soup.find("h2", string="Bins and Recycling")
63
+ if bins_panel:
64
+ panel = bins_panel.find_parent("div", class_="panel")
65
+ print("Found 'Bins and Recycling' panel.")
66
+
67
+ # Extract bin collection info from the un-commented HTML
68
+ for strong_tag in panel.find_all("strong"):
69
+ bin_type = strong_tag.text.strip()
70
+ collection_string = strong_tag.find_next("p").text.strip()
71
+
72
+ # Debugging output
73
+ print(f"Processing bin type: {bin_type}")
74
+ print(f"Collection string: {collection_string}")
75
+
76
+ match = regex_date.search(collection_string)
77
+ if match:
78
+ collection_date = datetime.strptime(match.group(1), "%d/%m/%Y").date()
79
+ data["bins"].append({
80
+ "type": bin_type,
81
+ "collectionDate": collection_date.strftime("%d/%m/%Y"),
82
+ })
83
+ all_collection_dates.append(collection_date)
84
+ else:
85
+ # Add a debug line to show which collections are missing dates
86
+ print(f"No valid date found for bin type: {bin_type}")
87
+
88
+ # Search for additional collections like electrical and textiles
89
+ for p in panel.find_all("p"):
90
+ additional_match = regex_additional_collection.match(p.text.strip())
91
+
92
+ # Debugging output for additional collections
93
+ if additional_match:
94
+ bin_type = additional_match.group(1)
95
+ print(f"Found additional collection: {bin_type}")
96
+ if "each collection day" in additional_match.group(2):
97
+ if all_collection_dates:
98
+ collection_date = min(all_collection_dates)
99
+ data["bins"].append({
78
100
  "type": bin_type,
79
101
  "collectionDate": collection_date.strftime("%d/%m/%Y"),
80
- }
81
- )
82
- all_collection_dates.append(collection_date)
83
-
84
- # Search for additional collections
85
- for p in panel.select("p"):
86
- m2 = regex_additional_collection.match(p.text.strip())
87
- if m2:
88
- bin_type = m2.group(1)
89
- if "each collection day" in m2.group(2):
90
- collection_date = min(all_collection_dates)
91
- data["bins"].append(
92
- {
93
- "type": bin_type,
94
- "collectionDate": collection_date.strftime(
95
- "%d/%m/%Y"
96
- ),
97
- }
98
- )
99
- break
100
-
101
- return data
102
+ })
103
+ else:
104
+ print("No collection dates available for additional collection.")
105
+ raise ValueError("No valid bin collection dates found.")
106
+ else:
107
+ print(f"No additional collection found in paragraph: {p.text.strip()}")
108
+ else:
109
+ raise ValueError("Unable to find 'Bins and Recycling' panel in the HTML data.")
110
+
111
+ # Debugging to check collected data
112
+ print(f"Collected bin data: {data}")
113
+
114
+ # Handle the case where no collection dates were found
115
+ if not all_collection_dates:
116
+ raise ValueError("No valid collection dates were found in the data.")
117
+
118
+ return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.98.1
3
+ Version: 0.98.3
4
4
  Summary: Python Lib to collect UK Bin Data
5
5
  Author: Robert Bradley
6
6
  Author-email: robbrad182@gmail.com
@@ -64,7 +64,7 @@ uk_bin_collection/uk_bin_collection/councils/EastCambridgeshireCouncil.py,sha256
64
64
  uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py,sha256=U0VwSNIldMv5nUoiXtFgjbE0m6Kb-8W2WZQGVCNF_WI,3261
65
65
  uk_bin_collection/uk_bin_collection/councils/EastLindseyDistrictCouncil.py,sha256=o_HPSFhb2ybmwv32_7T7CO1f2mGDkYCNPfaM5xz6bUI,4356
66
66
  uk_bin_collection/uk_bin_collection/councils/EastRenfrewshireCouncil.py,sha256=5giegMCKQ2JhVDR5M4mevVxIdhZtSW7kbuuoSkj3EGk,4361
67
- uk_bin_collection/uk_bin_collection/councils/EastRidingCouncil.py,sha256=CsYdkmL-8Ty-Kz7uNdlnJnhiDMgOPah_swYgSKbaFqA,5218
67
+ uk_bin_collection/uk_bin_collection/councils/EastRidingCouncil.py,sha256=oL-NqriLVy_NChGASNh8qTqeakLn4iP_XzoMC6VlPGM,5216
68
68
  uk_bin_collection/uk_bin_collection/councils/EastSuffolkCouncil.py,sha256=qQ0oOfGd0sWcczse_B22YoeL9uj3og8v3UJLt_Sx29c,4353
69
69
  uk_bin_collection/uk_bin_collection/councils/EastleighBoroughCouncil.py,sha256=V4Vso4DvawFiezKlmXbTlJEK9Sjhz9nA8WeYjwtO2e4,2310
70
70
  uk_bin_collection/uk_bin_collection/councils/ElmbridgeBoroughCouncil.py,sha256=TgBOaReHWBbm0avV7HqRf0x7cxDe9cacTUcP9TFFprs,3005
@@ -111,7 +111,7 @@ uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py,sha256=3Y2Un4xXo1s
111
111
  uk_bin_collection/uk_bin_collection/councils/MidAndEastAntrimBoroughCouncil.py,sha256=oOWwU5FSgGej2Mv7FQ66N-EzS5nZgmGsd0WnfLWUc1I,5238
112
112
  uk_bin_collection/uk_bin_collection/councils/MidSussexDistrictCouncil.py,sha256=AZgC9wmDLEjUOtIFvf0ehF5LHturXTH4DkE3ioPSVBA,6254
113
113
  uk_bin_collection/uk_bin_collection/councils/MiltonKeynesCityCouncil.py,sha256=3olsWa77L34vz-c7NgeGK9xmNuR4Ws_oAk5D4UpIkPw,2005
114
- uk_bin_collection/uk_bin_collection/councils/MoleValleyDistrictCouncil.py,sha256=54-autRRGAM4pBxlqmUE6g825rmUF-gRqrcgHL_lkIk,3994
114
+ uk_bin_collection/uk_bin_collection/councils/MoleValleyDistrictCouncil.py,sha256=bvCrC4Qcg0Uzp9zZGcC7-7-oJcMh2cb1VaXfdkB11oc,5257
115
115
  uk_bin_collection/uk_bin_collection/councils/NeathPortTalbotCouncil.py,sha256=V9URKAv3dA_deYmStL2Nmn4GbVCM-tU2qnKobivmGew,5583
116
116
  uk_bin_collection/uk_bin_collection/councils/NewForestCouncil.py,sha256=ylTn9KmWITtaO9_Z8kJCN2w2ALfhrfGt3SeJ78lgw7M,5391
117
117
  uk_bin_collection/uk_bin_collection/councils/NewarkAndSherwoodDC.py,sha256=lAleYfCGUWCKOi7Ye_cjgfpI3pWwTcFctlYmh0hjebM,2140
@@ -210,8 +210,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
210
210
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
211
211
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
212
212
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
213
- uk_bin_collection-0.98.1.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
214
- uk_bin_collection-0.98.1.dist-info/METADATA,sha256=dmWxsxgW5nOAahaqJsFqK-bn6f5rbGSQB9uq1x0EsYk,16843
215
- uk_bin_collection-0.98.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
216
- uk_bin_collection-0.98.1.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
217
- uk_bin_collection-0.98.1.dist-info/RECORD,,
213
+ uk_bin_collection-0.98.3.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
214
+ uk_bin_collection-0.98.3.dist-info/METADATA,sha256=tXTM95e75ygcLe_-4x6iPeWvmm7maK9V6VxrXjov5J0,16843
215
+ uk_bin_collection-0.98.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
216
+ uk_bin_collection-0.98.3.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
217
+ uk_bin_collection-0.98.3.dist-info/RECORD,,