uk_bin_collection 0.109.0__py3-none-any.whl → 0.109.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -279,6 +279,12 @@
279
279
  "web_driver": "http://selenium:4444",
280
280
  "wiki_name": "Cheshire West and Chester Council"
281
281
  },
282
+ "ChesterfieldBoroughCouncil": {
283
+ "uprn": "74008234",
284
+ "skip_get_url": true,
285
+ "url": "https://www.cheshirewestandchester.gov.uk/residents/waste-and-recycling/your-bin-collection/collection-day",
286
+ "wiki_name": "Chesterfield Borough Council"
287
+ },
282
288
  "ChichesterDistrictCouncil": {
283
289
  "house_number": "7, Plaistow Road, Kirdford, Billingshurst, West Sussex",
284
290
  "postcode": "RH14 0JT",
@@ -28,6 +28,7 @@ def council(request):
28
28
 
29
29
 
30
30
  @scenario("../features/validate_council_outputs.feature", "Validate Council Output")
31
+ @pytest.mark.no_homeassistant # Apply marker here
31
32
  def test_scenario_outline(council) -> None:
32
33
  pass
33
34
 
@@ -0,0 +1,175 @@
1
+ import json
2
+ import logging
3
+ import re
4
+ from datetime import datetime, timedelta
5
+
6
+ import requests
7
+ from bs4 import BeautifulSoup
8
+ from uk_bin_collection.uk_bin_collection.common import check_uprn, date_format
9
+ from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
10
+ import urllib3
11
+
12
+
13
+ # Suppress only the single warning from urllib3 needed.
14
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
15
+
16
+ _LOGGER = logging.getLogger(__name__)
17
+
18
+ class CouncilClass(AbstractGetBinDataClass):
19
+ """
20
+ Implementation for Chesterfield Borough Council waste collection data retrieval.
21
+ """
22
+
23
+ def parse_data(self, page: str, **kwargs) -> dict:
24
+ """
25
+ Fetch and parse waste collection data for Chesterfield Borough Council.
26
+
27
+ Args:
28
+ page (str): Not used in this implementation.
29
+ **kwargs: Should contain 'uprn' key.
30
+
31
+ Returns:
32
+ dict: Parsed bin collection data.
33
+ """
34
+ # Get and check UPRN
35
+ user_uprn = kwargs.get("uprn")
36
+ check_uprn(user_uprn)
37
+ bindata = {"bins": []}
38
+
39
+ # Define API URLs
40
+ API_URLS = {
41
+ "session": "https://www.chesterfield.gov.uk/bins-and-recycling/bin-collections/check-bin-collections.aspx",
42
+ "fwuid": "https://myaccount.chesterfield.gov.uk/anonymous/c/cbc_VE_CollectionDaysLO.app?aura.format=JSON&aura.formatAdapter=LIGHTNING_OUT",
43
+ "search": "https://myaccount.chesterfield.gov.uk/anonymous/aura?r=2&aura.ApexAction.execute=1",
44
+ }
45
+
46
+ HEADERS = {
47
+ "User-Agent": "Mozilla/5.0",
48
+ "Content-Type": "application/x-www-form-urlencoded",
49
+ }
50
+
51
+ # Initialize session
52
+ session = requests.Session()
53
+
54
+ try:
55
+ # Step 1: Get session
56
+ session.get(API_URLS["session"], headers=HEADERS, verify=False)
57
+
58
+ # Step 2: Get fwuid
59
+ fwuid_response = session.get(API_URLS["fwuid"], headers=HEADERS, verify=False)
60
+ fwuid_data = fwuid_response.json()
61
+ fwuid = fwuid_data.get("auraConfig", {}).get("context", {}).get("fwuid")
62
+
63
+ if not fwuid:
64
+ _LOGGER.error("Failed to retrieve fwuid from the response.")
65
+ return bindata
66
+
67
+ # Step 3: Prepare payload for UPRN search
68
+ payload = {
69
+ "message": json.dumps({
70
+ "actions": [{
71
+ "id": "4;a",
72
+ "descriptor": "aura://ApexActionController/ACTION$execute",
73
+ "callingDescriptor": "UNKNOWN",
74
+ "params": {
75
+ "namespace": "",
76
+ "classname": "CBC_VE_CollectionDays",
77
+ "method": "getServicesByUPRN",
78
+ "params": {
79
+ "propertyUprn": user_uprn,
80
+ "executedFrom": "Main Website"
81
+ },
82
+ "cacheable": False,
83
+ "isContinuation": False
84
+ }
85
+ }]
86
+ }),
87
+ "aura.context": json.dumps({
88
+ "mode": "PROD",
89
+ "fwuid": fwuid,
90
+ "app": "c:cbc_VE_CollectionDaysLO",
91
+ "loaded": {
92
+ "APPLICATION@markup://c:cbc_VE_CollectionDaysLO": "pqeNg7kPWCbx1pO8sIjdLA"
93
+ },
94
+ "dn": [],
95
+ "globals": {},
96
+ "uad": True
97
+ }),
98
+ "aura.pageURI": "/bins-and-recycling/bin-collections/check-bin-collections.aspx",
99
+ "aura.token": "null",
100
+ }
101
+
102
+ # Step 4: Make POST request to fetch collection data
103
+ search_response = session.post(
104
+ API_URLS["search"],
105
+ data=payload,
106
+ headers=HEADERS,
107
+ verify=False
108
+ )
109
+ search_data = search_response.json()
110
+
111
+ # Step 5: Extract service units
112
+ service_units = search_data.get("actions", [])[0].get("returnValue", {}).get("returnValue", {}).get("serviceUnits", [])
113
+
114
+ if not service_units:
115
+ _LOGGER.warning("No service units found for the given UPRN.")
116
+ return bindata
117
+
118
+ # Initialize dictionary to store bin dates
119
+ bin_schedule = {}
120
+
121
+ # Define icon mapping
122
+ ICON_MAP = {
123
+ "DOMESTIC REFUSE": "mdi:trash-can",
124
+ "DOMESTIC RECYCLING": "mdi:recycle",
125
+ "DOMESTIC ORGANIC": "mdi:leaf",
126
+ }
127
+
128
+ # Define regex pattern to capture day and date (e.g., Tue 5 Nov)
129
+ date_pattern = re.compile(r"\b\w{3} \d{1,2} \w{3}\b")
130
+
131
+ current_year = datetime.now().year
132
+
133
+ # Process each service unit
134
+ for item in service_units:
135
+ try:
136
+ waste_type = item["serviceTasks"][0]["taskTypeName"]
137
+ waste_type = str(waste_type).replace("Collect ", "").upper()
138
+ except (IndexError, KeyError):
139
+ _LOGGER.debug("Skipping a service unit due to missing data.")
140
+ continue
141
+
142
+ # Extract the next scheduled date
143
+ try:
144
+ dt_zulu = item["serviceTasks"][0]["serviceTaskSchedules"][0]["nextInstance"]["currentScheduledDate"]
145
+ dt_utc = datetime.strptime(dt_zulu, "%Y-%m-%dT%H:%M:%S.%f%z")
146
+ dt_local = dt_utc.astimezone(None)
147
+ collection_date = dt_local.date()
148
+ except (IndexError, KeyError, ValueError) as e:
149
+ _LOGGER.warning(f"Failed to parse date for {waste_type}: {e}")
150
+ continue
151
+
152
+ # Append to bin_schedule
153
+ bin_schedule[waste_type] = collection_date.strftime(date_format)
154
+
155
+ # Convert bin_schedule to the expected format
156
+ for bin_type, collection_date in bin_schedule.items():
157
+ dict_data = {
158
+ "type": bin_type,
159
+ "collectionDate": collection_date,
160
+ }
161
+ bindata["bins"].append(dict_data)
162
+
163
+ # Sort the bins by collection date
164
+ bindata["bins"].sort(
165
+ key=lambda x: datetime.strptime(x.get("collectionDate"), date_format)
166
+ )
167
+
168
+ except requests.RequestException as e:
169
+ _LOGGER.error(f"Network error occurred: {e}")
170
+ except json.JSONDecodeError as e:
171
+ _LOGGER.error(f"JSON decoding failed: {e}")
172
+ except Exception as e:
173
+ _LOGGER.error(f"An unexpected error occurred: {e}")
174
+
175
+ return bindata
@@ -2,7 +2,6 @@ from bs4 import BeautifulSoup
2
2
  from uk_bin_collection.uk_bin_collection.common import *
3
3
  from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
4
4
 
5
-
6
5
  # import the wonderful Beautiful Soup and the URL grabber
7
6
  class CouncilClass(AbstractGetBinDataClass):
8
7
  """
@@ -25,7 +24,7 @@ class CouncilClass(AbstractGetBinDataClass):
25
24
  dict_data = {
26
25
  "type": bin_type,
27
26
  "collectionDate": datetime.strptime(
28
- bin_collection.get_text(strip=True), "%A, %d %B %Y"
27
+ bin_collection.get_text(strip=True), date_format
29
28
  ),
30
29
  }
31
30
  data["bins"].append(dict_data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.109.0
3
+ Version: 0.109.1
4
4
  Summary: Python Lib to collect UK Bin Data
5
5
  Author: Robert Bradley
6
6
  Author-email: robbrad182@gmail.com
@@ -12,9 +12,6 @@ Requires-Dist: bs4
12
12
  Requires-Dist: holidays
13
13
  Requires-Dist: lxml
14
14
  Requires-Dist: pandas
15
- Requires-Dist: pytest-asyncio (>=0.24.0,<0.25.0)
16
- Requires-Dist: pytest-freezer (>=0.4.8,<0.5.0)
17
- Requires-Dist: pytest-homeassistant-custom-component (==0.13.175)
18
15
  Requires-Dist: python-dateutil
19
16
  Requires-Dist: requests
20
17
  Requires-Dist: selenium
@@ -2,10 +2,10 @@ 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=uYwhZO8IEhkNc0WzUaXTgcKuH76-l9MloWgIiEfoBcU,77866
5
+ uk_bin_collection/tests/input.json,sha256=mQ5rDFi-l9QHP6AvgNnxADOGtgdybTT24hOoEh7MkRI,78144
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
- uk_bin_collection/tests/step_defs/test_validate_council.py,sha256=LrOSt_loA1Mw3vTqaO2LpaDMu7rYJy6k5Kr-EOBln7s,3424
8
+ uk_bin_collection/tests/step_defs/test_validate_council.py,sha256=VZ0a81sioJULD7syAYHjvK_-nT_Rd36tUyzPetSA0gk,3475
9
9
  uk_bin_collection/tests/test_collect_data.py,sha256=xit4lopMGXb5g2faCK9VrOjHl81QDV9sZAu7vBdr2Uw,2253
10
10
  uk_bin_collection/tests/test_common_functions.py,sha256=WRm7AYI9qaDqW0dNROTFh-KZRdNFhhYHvjrFZUN4IPs,14084
11
11
  uk_bin_collection/tests/test_conftest.py,sha256=GWqP6-fCv5A2VUYiyXqUO-Dm0hlUOwbFgfi6CkdGqvQ,1061
@@ -50,6 +50,7 @@ uk_bin_collection/uk_bin_collection/councils/CharnwoodBoroughCouncil.py,sha256=t
50
50
  uk_bin_collection/uk_bin_collection/councils/ChelmsfordCityCouncil.py,sha256=EB88D0MNJwuDZ2GX1ENc5maGYx17mnHTCtNl6s-v11E,5090
51
51
  uk_bin_collection/uk_bin_collection/councils/CheshireEastCouncil.py,sha256=aMqT5sy1Z1gklFO5Xl893OgeBmpf19OwpizWEKWQ3hg,1680
52
52
  uk_bin_collection/uk_bin_collection/councils/CheshireWestAndChesterCouncil.py,sha256=xsJcx-Dcds0ZcX2vZ-xHVkCg-faQRvbhrJzRDY6Lguw,4779
53
+ uk_bin_collection/uk_bin_collection/councils/ChesterfieldBoroughCouncil.py,sha256=KtMasJBLed5qw15uzZ9bZ2ndy-ofCyu3MwCya6i9oig,6784
53
54
  uk_bin_collection/uk_bin_collection/councils/ChichesterDistrictCouncil.py,sha256=HxrLcJves7ZsE8FbooymeecTUmScY4R7Oi71vwCePPo,4118
54
55
  uk_bin_collection/uk_bin_collection/councils/ChorleyCouncil.py,sha256=M7HjuUaFq8aSnOf_9m1QS4MmPPMmPhF3mLHSrfDPtV0,5194
55
56
  uk_bin_collection/uk_bin_collection/councils/ColchesterCityCouncil.py,sha256=Mny-q2rQkWe2Tj1gINwEM1L4AkqQl1EDMAaKY0-deD4,3968
@@ -234,11 +235,11 @@ uk_bin_collection/uk_bin_collection/councils/WorcesterCityCouncil.py,sha256=dKHB
234
235
  uk_bin_collection/uk_bin_collection/councils/WychavonDistrictCouncil.py,sha256=GnNNMe33YMlK6S7rjM3c4BQkBnXelS0DKl2x5V4fb2w,5775
235
236
  uk_bin_collection/uk_bin_collection/councils/WyreCouncil.py,sha256=zDDa7n4K_zm5PgDL08A26gD9yOOsOhuexI3x2seaBF4,3511
236
237
  uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bIdsvmoSzBjJAvTTi6yPfJa8xjJx1ys2w,1490
237
- uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
238
+ uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=EQWRhZ2pEejlvm0fPyOTsOHKvUZmPnxEYO_OWRGKTjs,1158
238
239
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
239
240
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
240
- uk_bin_collection-0.109.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
241
- uk_bin_collection-0.109.0.dist-info/METADATA,sha256=9pDVW2X6eYSB-RxEqzQPe8OdqiQf5tGtNoPvKqstArA,17736
242
- uk_bin_collection-0.109.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
243
- uk_bin_collection-0.109.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
244
- uk_bin_collection-0.109.0.dist-info/RECORD,,
241
+ uk_bin_collection-0.109.1.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
242
+ uk_bin_collection-0.109.1.dist-info/METADATA,sha256=k1L8njxhEISbOUBLjK44nNQIvFv5F0DHDdLD-s3Vq_0,17574
243
+ uk_bin_collection-0.109.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
244
+ uk_bin_collection-0.109.1.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
245
+ uk_bin_collection-0.109.1.dist-info/RECORD,,