Skip to content

Commit

Permalink
feat: Adding Fife Council
Browse files Browse the repository at this point in the history
fix: #933
  • Loading branch information
m26dvd authored and robbrad committed Nov 6, 2024
1 parent 546f04f commit e79ce9b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 4 deletions.
7 changes: 7 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@
"url": "https://www.fenland.gov.uk/article/13114/",
"wiki_name": "Fenland District Council"
},
"FifeCouncil": {
"url": "https://www.fife.gov.uk",
"wiki_command_url_override": "https://www.fife.gov.uk",
"uprn": "320203521",
"wiki_name": "Fife Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"FlintshireCountyCouncil": {
"url": "https://digital.flintshire.gov.uk",
"wiki_command_url_override": "https://digital.flintshire.gov.uk",
Expand Down
68 changes: 68 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/FifeCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from datetime import datetime

import requests
from bs4 import BeautifulSoup

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass


class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
base class. They can also override some operations with a default
implementation.
"""

def parse_data(self, page: str, **kwargs) -> dict:
# Get and check UPRN
user_uprn = kwargs.get("uprn")
check_uprn(user_uprn)
bindata = {"bins": []}

API_URL = "https://www.fife.gov.uk/api/custom?action=powersuite_bin_calendar_collections&actionedby=bin_calendar&loadform=true&access=citizen&locale=en"
AUTH_URL = "https://www.fife.gov.uk/api/citizen?preview=false&locale=en"
AUTH_KEY = "Authorization"

r = requests.get(AUTH_URL)
r.raise_for_status()
auth_token = r.headers[AUTH_KEY]

post_data = {
"name": "bin_calendar",
"data": {
"uprn": user_uprn,
},
"email": "",
"caseid": "",
"xref": "",
"xref1": "",
"xref2": "",
}

headers = {
"referer": "https://www.fife.gov.uk/services/forms/bin-calendar",
"accept": "application/json",
"content-type": "application/json",
AUTH_KEY: auth_token,
}

r = requests.post(API_URL, data=json.dumps(post_data), headers=headers)
r.raise_for_status()

result = r.json()

for collection in result["data"]["tab_collections"]:
dict_data = {
"type": collection["colour"],
"collectionDate": datetime.strptime(
collection["date"],
"%A, %B %d, %Y",
).strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
)
return bindata
37 changes: 33 additions & 4 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Falkirk Council](#falkirk-council)
- [Fareham Borough Council](#fareham-borough-council)
- [Fenland District Council](#fenland-district-council)
- [Fife Council](#fife-council)
- [Flintshire County Council](#flintshire-county-council)
- [Forest of Dean District Council](#forest-of-dean-district-council)
- [Gateshead Council](#gateshead-council)
- [Gedling Borough Council](#gedling-borough-council)
Expand Down Expand Up @@ -996,6 +998,28 @@ Additional parameters:

---

### Fife Council
```commandline
python collect_data.py FifeCouncil https://www.fife.gov.uk -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.

---

### Flintshire County Council
```commandline
python collect_data.py FlintshireCountyCouncil https://digital.flintshire.gov.uk -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.

---

### Forest of Dean District Council
```commandline
python collect_data.py ForestOfDeanDistrictCouncil https://community.fdean.gov.uk/s/waste-collection-enquiry -s -p "XXXX XXX" -n XX -w http://HOST:PORT/
Expand Down Expand Up @@ -1421,10 +1445,14 @@ Note: Pass the house name/number plus the name of the street with the postcode p

### Midlothian Council
```commandline
python collect_data.py MidlothianCouncil https://www.midlothian.gov.uk/directory_record/XXXXXX/XXXXXX
python collect_data.py MidlothianCouncil https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days -s -p "XXXX XXX" -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-p` - postcode
- `-n` - house number

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.
Note: Pass the house name/number wrapped in double quotes along with the postcode parameter

---

Expand Down Expand Up @@ -2027,7 +2055,7 @@ Additional parameters:

### Southwark Council
```commandline
python collect_data.py SouthwarkCouncil https://www.southwark.gov.uk/bins/lookup/XXXXXXXX -u XXXXXXXX
python collect_data.py SouthwarkCouncil https://services.southwark.gov.uk/bins/lookup/XXXXXXXX -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN
Expand Down Expand Up @@ -2191,10 +2219,11 @@ Additional parameters:

### Teignbridge Council
```commandline
python collect_data.py TeignbridgeCouncil https://www.google.co.uk -u XXXXXXXX
python collect_data.py TeignbridgeCouncil https://www.google.co.uk -u XXXXXXXX -w http://HOST:PORT/
```
Additional parameters:
- `-u` - UPRN
- `-w` - remote Selenium web driver URL (required for Home Assistant)

Note: Provide Google as the URL as the real URL breaks the integration. You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.

Expand Down

0 comments on commit e79ce9b

Please sign in to comment.