uk_bin_collection 0.85.7__py3-none-any.whl → 0.86.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.
@@ -69,11 +69,11 @@
69
69
  "wiki_note": "In order to use this parser, you must provide a valid postcode and a uprn retrieved from the councils website for your specific address"
70
70
  },
71
71
  "BelfastCityCouncil": {
72
+ "postcode": "BT10 0GY",
72
73
  "skip_get_url": true,
74
+ "uprn": "185086469",
73
75
  "url": "https://online.belfastcity.gov.uk/find-bin-collection-day/Default.aspx",
74
- "wiki_name": "BelfastCityCouncil",
75
- "postcode": "BT10 0GY",
76
- "uprn": "185086469"
76
+ "wiki_name": "BelfastCityCouncil"
77
77
  },
78
78
  "BexleyCouncil": {
79
79
  "house_number": "1 Dorchester Avenue, Bexley",
@@ -298,8 +298,8 @@
298
298
  },
299
299
  "DorsetCouncil": {
300
300
  "skip_get_url": true,
301
- "url": "https://www.dorsetcouncil.gov.uk/",
302
301
  "uprn": "100040711049",
302
+ "url": "https://www.dorsetcouncil.gov.uk/",
303
303
  "wiki_name": "Dorset Council"
304
304
  },
305
305
  "DoverDistrictCouncil": {
@@ -360,12 +360,12 @@
360
360
  "wiki_name": "Eastleigh Borough Council"
361
361
  },
362
362
  "EnfieldCouncil": {
363
- "url": "https://www.enfield.gov.uk/services/rubbish-and-recycling/find-my-collection-day",
364
- "wiki_name": "Enfield Council",
365
- "skip_get_url": true,
366
- "postcode": "N13 5AJ",
367
363
  "house_number": "111",
368
- "web_driver": "http://selenium:4444"
364
+ "postcode": "N13 5AJ",
365
+ "skip_get_url": true,
366
+ "url": "https://www.enfield.gov.uk/services/rubbish-and-recycling/find-my-collection-day",
367
+ "web_driver": "http://selenium:4444",
368
+ "wiki_name": "Enfield Council"
369
369
  },
370
370
  "EnvironmentFirst": {
371
371
  "url": "https://environmentfirst.co.uk/house.php?uprn=100060055444",
@@ -599,9 +599,9 @@
599
599
  "postcode": "RH16 1SS",
600
600
  "skip_get_url": true,
601
601
  "url": "https://www.midsussex.gov.uk/waste-recycling/bin-collection/",
602
+ "web_driver": "http://selenium:4444",
602
603
  "wiki_name": "Mid Sussex District Council",
603
- "wiki_note": "Pass the name of the street with the house number parameter, wrapped in double quotes",
604
- "web_driver": "http://selenium:4444"
604
+ "wiki_note": "Pass the name of the street with the house number parameter, wrapped in double quotes"
605
605
  },
606
606
  "MiltonKeynesCityCouncil": {
607
607
  "uprn": "Fullers Slade",
@@ -813,6 +813,11 @@
813
813
  "wiki_name": "Rochford Council",
814
814
  "wiki_note": "No extra parameters are required. Dates presented should be read as 'week commencing'."
815
815
  },
816
+ "RotherhamCouncil": {
817
+ "url": "https://www.rotherham.gov.uk/bin-collections\\?address\\=100050866000\\&submit\\=Submit",
818
+ "uprn": "100050866000",
819
+ "wiki_name": "RotherhamCouncil"
820
+ },
816
821
  "RugbyBoroughCouncil": {
817
822
  "postcode": "CV22 6LA",
818
823
  "skip_get_url": true,
@@ -1199,12 +1204,12 @@
1199
1204
  "wiki_note": "Works with all collection areas that use Joint Waste Solutions. Just use the correct URL."
1200
1205
  },
1201
1206
  "WychavonDistrictCouncil": {
1207
+ "postcode": "WR3 7RU",
1208
+ "skip_get_url": true,
1209
+ "uprn": "100120716273",
1202
1210
  "url": "https://selfservice.wychavon.gov.uk/wdcroundlookup/wdc_search.jsp",
1203
- "wiki_name": "WychavonDistrictCouncil",
1204
1211
  "web_driver": "http://selenium:4444",
1205
- "skip_get_url": true,
1206
- "postcode": "WR3 7RU",
1207
- "uprn": "100120716273"
1212
+ "wiki_name": "WychavonDistrictCouncil"
1208
1213
  },
1209
1214
  "WyreCouncil": {
1210
1215
  "postcode": "FY6 8HG",
@@ -0,0 +1,51 @@
1
+ from bs4 import BeautifulSoup
2
+ from uk_bin_collection.uk_bin_collection.common import *
3
+ from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
4
+
5
+
6
+ # import the wonderful Beautiful Soup and the URL grabber
7
+ class CouncilClass(AbstractGetBinDataClass):
8
+ """
9
+ Concrete classes have to implement all abstract operations of the
10
+ base class. They can also override some operations with a default
11
+ implementation.
12
+ """
13
+
14
+ def parse_data(self, page: str, **kwargs) -> dict:
15
+ user_uprn = kwargs.get("uprn")
16
+
17
+ check_uprn(user_uprn)
18
+
19
+ response = requests.post(
20
+ "https://www.rotherham.gov.uk/bin-collections?address={}&submit=Submit".format(user_uprn)
21
+ )
22
+ # Make a BS4 object
23
+ soup = BeautifulSoup(response.text, features="html.parser")
24
+ soup.prettify()
25
+
26
+ data = {"bins": []}
27
+
28
+ table = soup.select('table')[0]
29
+
30
+ if table:
31
+ rows = table.select('tr')
32
+
33
+ for index, row in enumerate(rows):
34
+ bin_info_cell = row.select('td')
35
+ if bin_info_cell:
36
+ bin_type = bin_info_cell[0].get_text(separator=' ', strip=True)
37
+ bin_collection = bin_info_cell[1]
38
+
39
+ if bin_collection:
40
+ dict_data = {
41
+ "type": bin_type.title(),
42
+ "collectionDate": datetime.strptime(
43
+ bin_collection.get_text(strip=True), "%A, %d %B %Y"
44
+ ).strftime(date_format),
45
+ }
46
+
47
+ data["bins"].append(dict_data)
48
+ else:
49
+ print("Something went wrong. Please open a GitHub issue.")
50
+
51
+ return data
@@ -1,15 +1,11 @@
1
1
  from bs4 import BeautifulSoup
2
-
3
2
  from uk_bin_collection.uk_bin_collection.common import *
4
3
  from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
4
+ from datetime import datetime
5
5
 
6
-
7
- # import the wonderful Beautiful Soup and the URL grabber
8
6
  class CouncilClass(AbstractGetBinDataClass):
9
7
  """
10
- Concrete classes have to implement all abstract operations of the base
11
- class. They can also override some operations with a default
12
- implementation.
8
+ Concrete class to scrape bin collection data.
13
9
  """
14
10
 
15
11
  def parse_data(self, page: str, **kwargs) -> dict:
@@ -27,65 +23,71 @@ class CouncilClass(AbstractGetBinDataClass):
27
23
  soup.prettify()
28
24
 
29
25
  data = {"bins": []}
26
+ # Locate the section with bin collection data
30
27
  sections = soup.find_all("div", {"class": "wil_c-content-section_heading"})
28
+
31
29
  for s in sections:
32
30
  if s.get_text(strip=True).lower() == "bin collections":
33
31
  rows = s.find_next_sibling(
34
32
  "div", {"class": "c-content-section_body"}
35
- ).find_all("div", {"class": "u-mb-8"})
33
+ ).find_all("div", class_="tablet:l-col-fb-4 u-mt-10")
34
+
36
35
  for row in rows:
37
- title = row.find("div", {"class": "u-mb-4"})
38
- collections = row.find_all("div", {"class": "u-mb-2"})
39
- if title and collections:
36
+ title_elem = row.find("div", class_="u-mb-4")
37
+ if title_elem:
38
+ title = title_elem.get_text(strip=True).capitalize()
39
+
40
+ # Find all collection info in the same section
41
+ collections = row.find_all("div", class_="u-mb-2")
40
42
  for c in collections:
41
- if (
42
- c.get_text(strip=True)
43
- .lower()
44
- .startswith("next collection")
45
- ):
46
- # add next collection
47
- next_collection_date = datetime.strptime(
48
- c.get_text(strip=True).replace(
49
- "Next collection - ", ""
50
- ),
51
- "%A, %d %B %Y",
52
- ).strftime(date_format)
53
- dict_data = {
54
- "type": title.get_text(strip=True).capitalize(),
55
- "collectionDate": next_collection_date,
56
- }
57
- data["bins"].append(dict_data)
58
- # add future collections without duplicating next collection
59
- future_collections = row.find(
60
- "ul", {"class": "u-mt-4"}
61
- ).find_all("li")
62
- for c in future_collections:
43
+ text = c.get_text(strip=True).lower()
44
+
45
+ if "next collection" in text:
46
+ date_text = text.replace("next collection - ", "")
47
+ try:
48
+ next_collection_date = datetime.strptime(
49
+ date_text, "%A, %d %B %Y"
50
+ ).strftime(date_format)
51
+
52
+ dict_data = {
53
+ "type": title,
54
+ "collectionDate": next_collection_date
55
+ }
56
+ data["bins"].append(dict_data)
57
+ except ValueError:
58
+ # Skip if the date isn't a valid date
59
+ print(f"Skipping invalid date: {date_text}")
60
+
61
+ # Get future collections
62
+ future_collections_section = row.find("ul", class_="u-mt-4")
63
+ if future_collections_section:
64
+ future_collections = future_collections_section.find_all("li")
65
+ for future_collection in future_collections:
66
+ future_date_text = future_collection.get_text(strip=True)
67
+ try:
63
68
  future_collection_date = datetime.strptime(
64
- c.get_text(strip=True),
65
- "%A, %d %B %Y",
69
+ future_date_text, "%A, %d %B %Y"
66
70
  ).strftime(date_format)
67
- if (
68
- future_collection_date
69
- != next_collection_date
70
- ):
71
+
72
+ # Avoid duplicates of next collection date
73
+ if future_collection_date != next_collection_date:
71
74
  dict_data = {
72
- "type": title.get_text(
73
- strip=True
74
- ).capitalize(),
75
- "collectionDate": future_collection_date,
75
+ "type": title,
76
+ "collectionDate": future_collection_date
76
77
  }
77
78
  data["bins"].append(dict_data)
79
+ except ValueError:
80
+ # Skip if the future collection date isn't valid
81
+ print(f"Skipping invalid future date: {future_date_text}")
78
82
 
83
+ # Sort the collections by date
79
84
  data["bins"].sort(
80
85
  key=lambda x: datetime.strptime(x.get("collectionDate"), date_format)
81
86
  )
82
87
  except Exception as e:
83
- # Here you can log the exception if needed
84
88
  print(f"An error occurred: {e}")
85
- # Optionally, re-raise the exception if you want it to propagate
86
89
  raise
87
90
  finally:
88
- # This block ensures that the driver is closed regardless of an exception
89
91
  if driver:
90
92
  driver.quit()
91
93
  return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.85.7
3
+ Version: 0.86.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=mhfscmGyBmckPef5PwBNFLus437GxD8E6WBlKxhzY5I,59728
5
+ uk_bin_collection/tests/input.json,sha256=w1JMksNwhHC4EojFuBhlvn1NrPgrR1XojBqneb3hJyQ,59938
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
@@ -125,6 +125,7 @@ uk_bin_collection/uk_bin_collection/councils/RenfrewshireCouncil.py,sha256=VlWm-
125
125
  uk_bin_collection/uk_bin_collection/councils/RhonddaCynonTaffCouncil.py,sha256=wInyVG_0wRrX_dRO9qbAzPhlXDseXapj2zQhsISw8gg,3233
126
126
  uk_bin_collection/uk_bin_collection/councils/RochdaleCouncil.py,sha256=UTSwSw515VehGn4xkjjRhUlzS4lDj4hgna6y-4VW3uM,2379
127
127
  uk_bin_collection/uk_bin_collection/councils/RochfordCouncil.py,sha256=_J2Eb5gec2Gmv_QYzKHT6sQleDnIHsn-5qf-T6TM9X0,2613
128
+ uk_bin_collection/uk_bin_collection/councils/RotherhamCouncil.py,sha256=sjZ00iBdqn2kOvGsWyMpY3h-HWmfC_K6LQ2wz1X5WGg,1761
128
129
  uk_bin_collection/uk_bin_collection/councils/RugbyBoroughCouncil.py,sha256=a5ySLmFvvY56QMA7-bk6MVBxRp5tPBIBg4navH0eYas,4306
129
130
  uk_bin_collection/uk_bin_collection/councils/RushcliffeBoroughCouncil.py,sha256=wMtiYRirT585vtsEOIyXHugk7aEj3pvyVWBaAePdqtE,4005
130
131
  uk_bin_collection/uk_bin_collection/councils/RushmoorCouncil.py,sha256=ZsGnXjoEaOS6U7fI0w7-uqxayAHdNVKsJi2fqIWEls8,3375
@@ -165,7 +166,7 @@ uk_bin_collection/uk_bin_collection/councils/TorridgeDistrictCouncil.py,sha256=6
165
166
  uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py,sha256=8CvO-WgdKdvyaOf3TYc4XwME8ogAXojgB40oyGRL8Dw,4129
166
167
  uk_bin_collection/uk_bin_collection/councils/ValeofGlamorganCouncil.py,sha256=Phgb_ECiUOOkqOx6OsfsTHMCW5VQfRmOC2zgYIQhuZA,5044
167
168
  uk_bin_collection/uk_bin_collection/councils/ValeofWhiteHorseCouncil.py,sha256=5nZLbU5YVKNsJ2X_wuybrNLFAzjVAxkazu-bYP4IGXw,4292
168
- uk_bin_collection/uk_bin_collection/councils/WakefieldCityCouncil.py,sha256=9zW4C0WKbsDLCKvFyVYFpyvp20JbrWc4G0HzadqF8WQ,4466
169
+ uk_bin_collection/uk_bin_collection/councils/WakefieldCityCouncil.py,sha256=-xqJOzHTrT4jOB3rHPXFYeqLaHyK9XmCPi92whaYBhw,4671
169
170
  uk_bin_collection/uk_bin_collection/councils/WalthamForest.py,sha256=P7MMw0EhpRmDbbnHb25tY5_yvYuZUFwJ1br4TOv24sY,4997
170
171
  uk_bin_collection/uk_bin_collection/councils/WarwickDistrictCouncil.py,sha256=3WQrAxzYzKoV4LyOqNTp9xINVsNi1xW9t8etducGeag,1146
171
172
  uk_bin_collection/uk_bin_collection/councils/WaverleyBoroughCouncil.py,sha256=tp9l7vdgSGRzNNG0pDfnNuFj4D2bpRJUJmAiTJ6bM0g,4662
@@ -186,8 +187,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
186
187
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
187
188
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
188
189
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
189
- uk_bin_collection-0.85.7.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
190
- uk_bin_collection-0.85.7.dist-info/METADATA,sha256=QaL1Kok_IeZ67sAPpPQQBarqR_SHff1CY-3HPMTuoIM,16231
191
- uk_bin_collection-0.85.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
192
- uk_bin_collection-0.85.7.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
193
- uk_bin_collection-0.85.7.dist-info/RECORD,,
190
+ uk_bin_collection-0.86.1.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
191
+ uk_bin_collection-0.86.1.dist-info/METADATA,sha256=0Jhf4AjdTWOwmSNGJ_xLQNHjV-nrnLl0TXF6m_5_U8E,16231
192
+ uk_bin_collection-0.86.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
193
+ uk_bin_collection-0.86.1.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
194
+ uk_bin_collection-0.86.1.dist-info/RECORD,,