forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Pembrokeshire County Council (mampfes#2755)
* Added api calls to find bin dates * Added markdown file * Updated README and info markdown files * Added dict of better formatted bin types * Correcting bin type strings to fit other formatting * Changed from using eval to literal_eval * reformatting + ./update_docu_links.py --------- Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
1 parent
eaab185
commit 5e17519
Showing
8 changed files
with
244 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...onents/waste_collection_schedule/waste_collection_schedule/source/pembrokeshire_gov_uk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import ast | ||
from datetime import datetime | ||
|
||
import requests | ||
from waste_collection_schedule import Collection | ||
|
||
TITLE = "Pembrokeshire County Council" # Title will show up in README.md and info.md | ||
DESCRIPTION = "Source script for pembrokeshire.gov.uk" # Describe your source | ||
URL = "https://www.pembrokeshire.gov.uk/" # Insert url to service homepage. URL will show up in README.md and info.md | ||
TEST_CASES = { # Insert arguments for test cases to be used by test_sources.py script | ||
"Dew Street": {"uprn": "100100283349"}, | ||
"Heol Cleddau": {"uprn": "100100281816"}, | ||
} | ||
|
||
API_URL = "https://www.pembrokeshire.gov.uk/template/waste/api.asp" | ||
|
||
TYPE_MAP = { # Dict of waste formatted bin types | ||
"FOODCAD": "GREEN CADDY", | ||
"BLUEBOX": "BLUE BOX", | ||
"GREENBOX": "GREEN BOX", | ||
"BLUEBAG": "BLUE BAG", | ||
"REDBAG": "RED BAG", | ||
"GREYBAG": "BLACK/GREY BAGS", | ||
} | ||
ICON_MAP = { # Optional: Dict of waste types and suitable mdi icons | ||
"FOODCAD": "mdi:food-apple", | ||
"BLUEBOX": "mdi:note-multiple", | ||
"GREENBOX": "mdi:glass-fragile", | ||
"BLUEBAG": "mdi:recycle", | ||
"REDBAG": "mdi:recycle", | ||
"GREYBAG": "mdi:trash-can", | ||
} | ||
|
||
# ### Arguments affecting the configuration GUI #### | ||
|
||
HOW_TO_GET_ARGUMENTS_DESCRIPTION = { # Optional dictionary to describe how to get the arguments, will be shown in the GUI configuration form above the input fields, does not need to be translated in all languages | ||
"en": "To get your UPRN go to https://www.findmyaddress.co.uk and search for your address.", | ||
} | ||
|
||
PARAM_DESCRIPTIONS = { # Optional dict to describe the arguments, will be shown in the GUI configuration below the respective input field | ||
"en": { | ||
"uprn": "Unique Property Reference Number (UPRN)", | ||
}, | ||
} | ||
|
||
# ### End of arguments affecting the configuration GUI #### | ||
|
||
|
||
class Source: | ||
def __init__( | ||
self, uprn: str | ||
): # argX correspond to the args dict in the source configuration | ||
self._uprn = uprn | ||
|
||
def fetch(self) -> list[Collection]: | ||
session = requests.Session() | ||
|
||
form_data = { | ||
"action": "dates", | ||
"public": "true", | ||
"uprn": self._uprn, | ||
"language": "eng", | ||
} | ||
|
||
collection_response = session.post(API_URL, params=form_data) | ||
|
||
if ast.literal_eval(collection_response.text)["error"] == "true": | ||
raise Exception("No collections found for the given UPRN.") | ||
|
||
entries = [] # List that holds collection schedule | ||
|
||
bin_dates = ast.literal_eval(collection_response.text)["bins"] | ||
for bin in bin_dates: | ||
date_string = bin["nextdate"] | ||
date_format = "%d/%m/%Y" | ||
date = datetime.strptime(date_string, date_format).date() | ||
bin_type = bin["type"] | ||
|
||
entries.append( | ||
Collection( | ||
date=date, # Collection date | ||
t=TYPE_MAP.get(bin_type), # Collection type | ||
icon=ICON_MAP.get(bin_type), # Collection icon | ||
) | ||
) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Pembrokeshire County Council | ||
|
||
Bin collection schedules provided by [Pembrokeshire County Council](https://www.pembrokeshire.gov.uk/) in Wales, UK. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: pembrokeshire_gov_uk | ||
args: | ||
uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER | ||
``` | ||
|
||
### Configuration Variables | ||
|
||
**UPRN** | ||
*(string)(required)* | ||
|
||
The "Unique Property Reference Number" for your address. You can find it by searching for your address at https://www.findmyaddress.co.uk/. | ||
|
||
## Example | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: pembrokeshire_gov_uk | ||
args: | ||
uprn: "100100283349" | ||
``` | ||
|
||
## Returned collection types | ||
|
||
### Food | ||
|
||
Green Caddy for food recycling | ||
|
||
### Paper | ||
|
||
Blue Box for paper recycling | ||
|
||
### Glass | ||
|
||
Green box for glass recycling | ||
|
||
### Cardboard | ||
|
||
Blue Bag for cardboard recycling | ||
|
||
### Plastics | ||
|
||
Red Bag for plastics recycling | ||
|
||
### Non-Recyclables | ||
|
||
Black/Grey Bags for non-recyclable waste |
Oops, something went wrong.