uk_bin_collection 0.100.0__py3-none-any.whl → 0.101.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -719,6 +719,12 @@
719
719
  "wiki_name": "Mid and East Antrim Borough Council",
720
720
  "wiki_note": "Pass the house name/number plus the name of the street with the postcode parameter, wrapped in double quotes. Check the address in the web site first. This version will only pick the first SHOW button returned by the search or if it is fully unique. The search is not very predictable (e.g. house number 4 returns 14,24,4,44 etc.)."
721
721
  },
722
+ "MidlothianCouncil": {
723
+ "url": "https://www.midlothian.gov.uk/directory_record/92551426/glenesk_bonnyrigg_eh19_3je",
724
+ "wiki_command_url_override": "https://www.midlothian.gov.uk/directory_record/XXXXXX/XXXXXX",
725
+ "wiki_name": "Midlothian Council",
726
+ "wiki_note": "Follow the instructions [here](https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days) until you get the page that shows the weekly collections for your address then copy the URL and replace the URL in the command."
727
+ },
722
728
  "MidSussexDistrictCouncil": {
723
729
  "house_number": "OAKLANDS, OAKLANDS ROAD RH16 1SS",
724
730
  "postcode": "RH16 1SS",
@@ -0,0 +1,68 @@
1
+ from bs4 import BeautifulSoup
2
+
3
+ from uk_bin_collection.uk_bin_collection.common import *
4
+ from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
5
+
6
+
7
+ # import the wonderful Beautiful Soup and the URL grabber
8
+ class CouncilClass(AbstractGetBinDataClass):
9
+ """
10
+ Concrete classes have to implement all abstract operations of the
11
+ base class. They can also override some operations with a default
12
+ implementation.
13
+ """
14
+
15
+ def parse_data(self, page: str, **kwargs) -> dict:
16
+ # Parse the HTML content using BeautifulSoup
17
+ soup = BeautifulSoup(page.text, features="html.parser")
18
+
19
+ # Initialize a dictionary to store the parsed bin data
20
+ data = {"bins": []}
21
+
22
+ # Define a mapping of bin collection labels to their corresponding types
23
+ bin_types = {
24
+ "Next recycling collection": "Recycling",
25
+ "Next grey bin collection": "Grey Bin",
26
+ "Next brown bin collection": "Brown Bin",
27
+ "Next food bin collection": "Food Bin",
28
+ }
29
+
30
+ # Locate the <ul> element with the class "data-table"
31
+ bin_collections = soup.find("ul", {"class": "data-table"})
32
+
33
+ # Proceed only if the <ul> element is found
34
+ if bin_collections:
35
+ # Retrieve all <li> elements within the <ul>, skipping the first two (not relevant)
36
+ bin_items = bin_collections.find_all("li")[2:]
37
+
38
+ # Iterate through each bin item
39
+ for bin in bin_items:
40
+ bin_type = None
41
+ # Retrieve the bin type from the header if it exists
42
+ if bin.h2 and bin.h2.text.strip() in bin_types:
43
+ bin_type = bin_types[bin.h2.text.strip()]
44
+
45
+ bin_collection_date = None
46
+ # Retrieve the bin collection date from the div if it exists
47
+ if bin.div and bin.div.text.strip():
48
+ try:
49
+ # Parse the collection date from the div text and format it
50
+ bin_collection_date = datetime.strptime(
51
+ bin.div.text.strip(),
52
+ "%A %d/%m/%Y",
53
+ ).strftime(date_format)
54
+ except ValueError:
55
+ # If date parsing fails, keep bin_collection_date as None
56
+ pass
57
+
58
+ # If both bin type and collection date are identified, add to the data
59
+ if bin_type and bin_collection_date:
60
+ data["bins"].append(
61
+ {
62
+ "type": bin_type,
63
+ "collectionDate": bin_collection_date,
64
+ }
65
+ )
66
+
67
+ # Return the parsed data, which may be empty if no bins were found
68
+ return data
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: uk_bin_collection
3
- Version: 0.100.0
3
+ Version: 0.101.0
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=zXnq55cYrh5bE9mLnWEk8e0ksHpZWzZJzewZeipG6x8,70569
5
+ uk_bin_collection/tests/input.json,sha256=tzx_1v1h_XLo3-dJHd5vHnX97dIJVHFjjAkC4allAXc,71114
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
@@ -112,6 +112,7 @@ uk_bin_collection/uk_bin_collection/councils/MansfieldDistrictCouncil.py,sha256=
112
112
  uk_bin_collection/uk_bin_collection/councils/MertonCouncil.py,sha256=3Y2Un4xXo1sCcMsudynODSzocV_mMofWkX2JqONDb5o,1997
113
113
  uk_bin_collection/uk_bin_collection/councils/MidAndEastAntrimBoroughCouncil.py,sha256=oOWwU5FSgGej2Mv7FQ66N-EzS5nZgmGsd0WnfLWUc1I,5238
114
114
  uk_bin_collection/uk_bin_collection/councils/MidSussexDistrictCouncil.py,sha256=AZgC9wmDLEjUOtIFvf0ehF5LHturXTH4DkE3ioPSVBA,6254
115
+ uk_bin_collection/uk_bin_collection/councils/MidlothianCouncil.py,sha256=3K3X7kv1oOJkZm2ivnT8Lx0GAzPefgFSHjruwcFgO7I,2821
115
116
  uk_bin_collection/uk_bin_collection/councils/MiltonKeynesCityCouncil.py,sha256=3olsWa77L34vz-c7NgeGK9xmNuR4Ws_oAk5D4UpIkPw,2005
116
117
  uk_bin_collection/uk_bin_collection/councils/MoleValleyDistrictCouncil.py,sha256=bvCrC4Qcg0Uzp9zZGcC7-7-oJcMh2cb1VaXfdkB11oc,5257
117
118
  uk_bin_collection/uk_bin_collection/councils/NeathPortTalbotCouncil.py,sha256=ychYR2nsyk2UIb8tjWaKrLUT4hxSsHN558l3RqZ0mjw,5635
@@ -217,8 +218,8 @@ uk_bin_collection/uk_bin_collection/councils/YorkCouncil.py,sha256=I2kBYMlsD4bId
217
218
  uk_bin_collection/uk_bin_collection/councils/council_class_template/councilclasstemplate.py,sha256=4s9ODGPAwPqwXc8SrTX5Wlfmizs3_58iXUtHc4Ir86o,1162
218
219
  uk_bin_collection/uk_bin_collection/create_new_council.py,sha256=m-IhmWmeWQlFsTZC4OxuFvtw5ZtB8EAJHxJTH4O59lQ,1536
219
220
  uk_bin_collection/uk_bin_collection/get_bin_data.py,sha256=YvmHfZqanwrJ8ToGch34x-L-7yPe31nB_x77_Mgl_vo,4545
220
- uk_bin_collection-0.100.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
221
- uk_bin_collection-0.100.0.dist-info/METADATA,sha256=3ZZbEhXFX2oIm-b-DbCqLelxuboNyfxOohMDxy4C9Wk,16844
222
- uk_bin_collection-0.100.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
223
- uk_bin_collection-0.100.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
224
- uk_bin_collection-0.100.0.dist-info/RECORD,,
221
+ uk_bin_collection-0.101.0.dist-info/LICENSE,sha256=vABBUOzcrgfaTKpzeo-si9YVEun6juDkndqA8RKdKGs,1071
222
+ uk_bin_collection-0.101.0.dist-info/METADATA,sha256=fcu_gjSU7JVGJ-O_7ZXo9HUj1YVcS4JeKJQ-zZnhNDA,16844
223
+ uk_bin_collection-0.101.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
224
+ uk_bin_collection-0.101.0.dist-info/entry_points.txt,sha256=36WCSGMWSc916S3Hi1ZkazzDKHaJ6CD-4fCEFm5MIao,90
225
+ uk_bin_collection-0.101.0.dist-info/RECORD,,