forked from robbrad/UKBinCollectionData
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding Redcar and Cleveland Council
fix: robbrad#841
- Loading branch information
Showing
3 changed files
with
130 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
108 changes: 108 additions & 0 deletions
108
uk_bin_collection/uk_bin_collection/councils/RedcarandClevelandCouncil.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,108 @@ | ||
import time | ||
|
||
import requests | ||
|
||
from uk_bin_collection.uk_bin_collection.common import * | ||
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass | ||
|
||
|
||
# import the wonderful Beautiful Soup and the URL grabber | ||
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_postcode = kwargs.get("postcode") | ||
user_paon = kwargs.get("paon") | ||
check_postcode(user_postcode) | ||
check_paon(user_paon) | ||
bindata = {"bins": []} | ||
|
||
URI = "https://api.eu.recollect.net/api/areas/RedcarandClevelandUK/services/50006/address-suggest" | ||
|
||
params = { | ||
"q": user_postcode, | ||
"locale": "en-GB", | ||
"_": str(int(time.time() * 1000)), | ||
} | ||
|
||
# print(params) | ||
|
||
# Send GET request | ||
response = requests.get(URI, params=params) | ||
|
||
addresses = response.json() | ||
|
||
place_id = next( | ||
( | ||
item["place_id"] | ||
for item in addresses | ||
if item.get("name", "").startswith(user_paon) | ||
), | ||
None, | ||
) | ||
|
||
# print(addresses) | ||
# print(place_id) | ||
|
||
URI = ( | ||
f"https://api.eu.recollect.net/api/places/{place_id}/services/50006/events" | ||
) | ||
|
||
after = datetime.today() | ||
before = after + timedelta(days=30) | ||
|
||
after = after.strftime("%Y-%m-%d") | ||
before = before.strftime("%Y-%m-%d") | ||
|
||
# print(after) | ||
# print(before) | ||
|
||
params = { | ||
"nomerge": 1, | ||
"hide": "reminder_only", | ||
"after": after, | ||
"before": before, | ||
"locale": "en-GB", | ||
"include_message": "email", | ||
"_": str(int(time.time() * 1000)), | ||
} | ||
|
||
# print(params) | ||
|
||
# Send GET request | ||
response = requests.get(URI, params=params) | ||
|
||
response = response.json() | ||
|
||
bin_collection = response["events"] | ||
|
||
# print(bin_collection) | ||
|
||
# Extract "end_day" and "name" | ||
events = [ | ||
(event["end_day"], flag["name"]) | ||
for event in bin_collection | ||
for flag in event.get("flags", []) | ||
] | ||
|
||
# Print results | ||
for end_day, bin_type in events: | ||
|
||
date = datetime.strptime(end_day, "%Y-%m-%d") | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": date.strftime(date_format), | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
bindata["bins"].sort( | ||
key=lambda x: datetime.strptime(x.get("collectionDate"), date_format) | ||
) | ||
|
||
return bindata |
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