-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1189 from geekball/feat-medway-council
feat: implement Medway Council (#1021)
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.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,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 |