Skip to content

Commit

Permalink
Merge pull request #1189 from geekball/feat-medway-council
Browse files Browse the repository at this point in the history
feat: implement Medway Council (#1021)
  • Loading branch information
robbrad authored Jan 28, 2025
2 parents f7f8b42 + 0b101d1 commit 34239d7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 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 @@ -1123,6 +1123,13 @@
"wiki_name": "Mansfield District Council",
"wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"MedwayCouncil": {
"skip_get_url": true,
"uprn": "200000907059",
"url": "https://www.medway.gov.uk/homepage/45/check_your_waste_collection_day",
"wiki_name": "MedwayCouncil",
"wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"MertonCouncil": {
"url": "https://myneighbourhood.merton.gov.uk/wasteservices/WasteServices.aspx?ID=25936129",
"wiki_command_url_override": "https://myneighbourhood.merton.gov.uk/Wasteservices/WasteServices.aspx?ID=XXXXXXXX",
Expand Down
40 changes: 40 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import json
from datetime import timedelta

import requests

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:
user_uprn = kwargs.get("uprn")
check_uprn(user_uprn)

api_url = f"https://api.medway.gov.uk/api/waste/getwasteday/{user_uprn}"

response = requests.get(api_url)

data = {"bins": []}

# If the response is 200, then we can parse the data; if not, we return an empty dict
if response.status_code == 200:
json_data = json.loads(response.text)
if json_data:
next_date = datetime.strptime(
json_data["nextCollection"], "%Y-%m-%dT%H:%M:%S%z"
)
dict_data = {
"type": "All bins",
"collectionDate": next_date.strftime(date_format),
}
data["bins"].append(dict_data)

return data

0 comments on commit 34239d7

Please sign in to comment.