uk_bin_collection 0.83.0__py3-none-any.whl → 0.84.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.
@@ -247,6 +247,13 @@
247
247
  "wiki_name": "Conwy County Borough Council",
248
248
  "wiki_note": "Conwy County Borough Council is a straight up uprn in the url eg &uprn=XXXXXXXXXXXXX ."
249
249
  },
250
+ "CornwallCouncil": {
251
+ "skip_get_url": true,
252
+ "uprn": "100040128734",
253
+ "url": "https://www.cornwall.gov.uk/my-area/",
254
+ "wiki_name": "Cornwall Council",
255
+ "wiki_note": "Use https://uprn.uk/ to find your UPRN."
256
+ },
250
257
  "CrawleyBoroughCouncil": {
251
258
  "house_number": "9701076",
252
259
  "skip_get_url": true,
@@ -1,4 +1,6 @@
1
1
  import time
2
+ import re
3
+
2
4
  from datetime import datetime
3
5
 
4
6
  from bs4 import BeautifulSoup
@@ -80,7 +82,8 @@ class CouncilClass(AbstractGetBinDataClass):
80
82
  bin_type = " ".join(words).capitalize()
81
83
  date_list = item.find_all("p")
82
84
  for d in date_list:
83
- next_collection = datetime.strptime(d.text.strip(), "%A %d %B %Y")
85
+ clean_date_str = re.sub(r'[^A-Za-z0-9 ]+', '', d.text.strip())
86
+ next_collection = datetime.strptime(clean_date_str, "%A %d %B %Y")
84
87
  collections.append((bin_type, next_collection))
85
88
 
86
89
  # Sort the text and list elements by date
@@ -0,0 +1,70 @@
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
+ from dateutil.relativedelta import relativedelta
5
+
6
+
7
+
8
+ # import the wonderful Beautiful Soup and the URL grabber
9
+ class CouncilClass(AbstractGetBinDataClass):
10
+ """
11
+ Concrete classes have to implement all abstract operations of the
12
+ base class. They can also override some operations with a default
13
+ implementation.
14
+ """
15
+
16
+ def parse_data(self, page: str, **kwargs) -> dict:
17
+ data = {"bins": []}
18
+ collections = []
19
+
20
+ curr_date = datetime.today()
21
+
22
+ user_uprn = kwargs.get("uprn")
23
+ check_uprn(user_uprn)
24
+
25
+ headers = {
26
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
27
+ 'Accept-Language': 'en-GB,en;q=0.9',
28
+ 'Cache-Control': 'no-cache',
29
+ 'Connection': 'keep-alive',
30
+ 'Pragma': 'no-cache',
31
+ 'Sec-Fetch-Dest': 'document',
32
+ 'Sec-Fetch-Mode': 'navigate',
33
+ 'Sec-Fetch-Site': 'none',
34
+ 'Sec-Fetch-User': '?1',
35
+ 'Upgrade-Insecure-Requests': '1',
36
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.6422.143 Safari/537.36',
37
+ 'sec-ch-ua': '"Opera GX";v="111", "Chromium";v="125", "Not.A/Brand";v="24"',
38
+ 'sec-ch-ua-mobile': '?0',
39
+ 'sec-ch-ua-platform': '"Windows"',
40
+ }
41
+ params = {
42
+ 'uprn': f'{user_uprn}',
43
+ # 'uprn': f'100040128734',
44
+ }
45
+ response = requests.get(
46
+ 'https://www.cornwall.gov.uk/umbraco/surface/waste/MyCollectionDays',
47
+ params=params,
48
+ headers=headers
49
+ )
50
+
51
+ soup = BeautifulSoup(response.text, features="html.parser")
52
+ soup.prettify()
53
+
54
+ for item in soup.find_all('div', class_='collection text-center service'):
55
+ bin_type = item.contents[1].text + " bin"
56
+ collection_date = datetime.strptime(item.contents[5].text, "%d %b").replace(year=curr_date.year)
57
+ if curr_date.month == 12 and collection_date.month == 1:
58
+ collection_date = collection_date + relativedelta(years=1)
59
+ collections.append((bin_type, collection_date))
60
+
61
+ ordered_data = sorted(collections, key=lambda x: x[1])
62
+ data = {"bins": []}
63
+ for bin in ordered_data:
64
+ dict_data = {
65
+ "type": bin[0].capitalize().strip(),
66
+ "collectionDate": bin[1].strftime(date_format),
67
+ }
68
+ data["bins"].append(dict_data)
69
+
70
+ return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.83.0
3
+ Version: 0.84.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=axAMaI3oqEgnSMsPpiRz-bP0F1dyOVQlcQqLQGZvFss,58837
5
+ uk_bin_collection/tests/input.json,sha256=OVMlr2sTqDMgQGlSgTQ1_LeuxXpVgXPvqRb_zGV95r8,59090
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
@@ -23,7 +23,7 @@ uk_bin_collection/uk_bin_collection/councils/BedfordshireCouncil.py,sha256=U1HOr
23
23
  uk_bin_collection/uk_bin_collection/councils/BexleyCouncil.py,sha256=9MrbpfR17R6DYjDrItQL3CPF7ie1SJkaoNbwQumPgIQ,5399
24
24
  uk_bin_collection/uk_bin_collection/councils/BirminghamCityCouncil.py,sha256=yrO9dnSMdqVTcrzqXXfexFxSuESW01VPxXNAl0_lNOU,4669
25
25
  uk_bin_collection/uk_bin_collection/councils/BlackburnCouncil.py,sha256=jHbCK8sL09vdmdP7Xnh8lIrU5AHTnJLEZfOLephPvWg,4090
26
- uk_bin_collection/uk_bin_collection/councils/BoltonCouncil.py,sha256=MrSzfK3EukRVasgP1nxAqg3lTkZzlAkDLJ2Nu5dJJ-0,4023
26
+ uk_bin_collection/uk_bin_collection/councils/BoltonCouncil.py,sha256=r7wjrRPT2EinRMnYjGxmsCD6aMFhEOyRNd8_3R9PdQU,4117
27
27
  uk_bin_collection/uk_bin_collection/councils/BracknellForestCouncil.py,sha256=Llo1rULaAZ8rChVYZqXFFLo7CN6vbT0ULUJD6ActouY,9015
28
28
  uk_bin_collection/uk_bin_collection/councils/BradfordMDC.py,sha256=9EDTdhbGb8BQ5PLEw9eiWZ3BrS0TtoFpYOHQU44wc2k,4308
29
29
  uk_bin_collection/uk_bin_collection/councils/BrightonandHoveCityCouncil.py,sha256=k6qt4cds-Ejd97Z-__pw2BYvGVbFdc9SUfF73PPrTNA,5823
@@ -43,6 +43,7 @@ uk_bin_collection/uk_bin_collection/councils/CheshireWestAndChesterCouncil.py,sh
43
43
  uk_bin_collection/uk_bin_collection/councils/ChichesterDistrictCouncil.py,sha256=HxrLcJves7ZsE8FbooymeecTUmScY4R7Oi71vwCePPo,4118
44
44
  uk_bin_collection/uk_bin_collection/councils/ChorleyCouncil.py,sha256=M7HjuUaFq8aSnOf_9m1QS4MmPPMmPhF3mLHSrfDPtV0,5194
45
45
  uk_bin_collection/uk_bin_collection/councils/ConwyCountyBorough.py,sha256=el75qv2QyfWZBU09tJLvD8vLQZ9pCg73u1NBFs6ybo8,1034
46
+ uk_bin_collection/uk_bin_collection/councils/CornwallCouncil.py,sha256=W7_wWHLbE0cyE90GkNaZHmR7Lbd2Aq48A1hKMUNO-vg,2806
46
47
  uk_bin_collection/uk_bin_collection/councils/CrawleyBoroughCouncil.py,sha256=_BEKZAjlS5Ad5DjyxqAEFSLn8F-KYox0zmn4BXaAD6A,2367
47
48
  uk_bin_collection/uk_bin_collection/councils/CroydonCouncil.py,sha256=QJH27plySbbmoNcLNUXq-hUiFmZ5zBlRS5mzOJgWSK8,11594
48
49
  uk_bin_collection/uk_bin_collection/councils/DartfordBoroughCouncil.py,sha256=SPirUUoweMwX5Txtsr0ocdcFtKxCQ9LhzTTJN20tM4w,1550
@@ -181,8 +182,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
181
182
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
182
183
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
183
184
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
184
- uk_bin_collection-0.83.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
185
- uk_bin_collection-0.83.0.dist-info/METADATA,sha256=dQnIai2UXeWBHq7XT6RpmmO59I670LzuoZ5t_PBgNDY,16231
186
- uk_bin_collection-0.83.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
187
- uk_bin_collection-0.83.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
188
- uk_bin_collection-0.83.0.dist-info/RECORD,,
185
+ uk_bin_collection-0.84.1.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
186
+ uk_bin_collection-0.84.1.dist-info/METADATA,sha256=nW0yhLZt4-z3n5GsVUfl4_-6pae8DiR67zXNcKuhel8,16231
187
+ uk_bin_collection-0.84.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
188
+ uk_bin_collection-0.84.1.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
189
+ uk_bin_collection-0.84.1.dist-info/RECORD,,