-
Notifications
You must be signed in to change notification settings - Fork 100
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 #872 from m26dvd/master
- Loading branch information
Showing
4 changed files
with
170 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
54 changes: 54 additions & 0 deletions
54
uk_bin_collection/uk_bin_collection/councils/FalkirkCouncil.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,54 @@ | ||
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_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
bindata = {"bins": []} | ||
|
||
URI = f"https://recycling.falkirk.gov.uk/api/collections/{user_uprn}" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the JSON response | ||
bin_collection = response.json() | ||
|
||
# Loop through each collection in bin_collection | ||
for collection in bin_collection["collections"]: | ||
bin_type = collection["type"] | ||
collection_dates = collection["dates"] | ||
|
||
# Loop through the dates for each collection type | ||
for date in collection_dates: | ||
print(f"Bin Type: {bin_type}") | ||
print(f"Collection Date: {date}") | ||
|
||
dict_data = { | ||
"type": bin_type, | ||
"collectionDate": datetime.strptime( | ||
date, | ||
"%Y-%m-%d", | ||
).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 |
46 changes: 46 additions & 0 deletions
46
uk_bin_collection/uk_bin_collection/councils/LondonBoroughHarrow.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,46 @@ | ||
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_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
bindata = {"bins": []} | ||
|
||
# Construct the URI | ||
URI = f"https://www.harrow.gov.uk/ajax/bins?u={user_uprn}&r=12345" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the JSON response | ||
bin_collection = response.json() | ||
|
||
# Loop through all collections and extract bin type and collection date | ||
for collection in bin_collection["results"]["collections"]["all"]: | ||
|
||
CollectTime = (collection["eventTime"]).split("T")[0] | ||
print(CollectTime) | ||
|
||
dict_data = { | ||
"type": collection["binType"], | ||
"collectionDate": datetime.strptime(CollectTime, "%Y-%m-%d").strftime( | ||
"%d/%m/%Y" | ||
), | ||
} | ||
bindata["bins"].append(dict_data) | ||
|
||
return bindata |
49 changes: 49 additions & 0 deletions
49
uk_bin_collection/uk_bin_collection/councils/NorthAyrshireCouncil.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,49 @@ | ||
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_uprn = kwargs.get("uprn") | ||
check_uprn(user_uprn) | ||
bindata = {"bins": []} | ||
|
||
URI = f"https://www.maps.north-ayrshire.gov.uk/arcgis/rest/services/AGOL/YourLocationLive/MapServer/8/query?f=json&outFields=*&returnDistinctValues=true&returnGeometry=false&spatialRel=esriSpatialRelIntersects&where=UPRN%20%3D%20%27{user_uprn}%27" | ||
|
||
# Make the GET request | ||
response = requests.get(URI) | ||
|
||
# Parse the JSON response | ||
result_json = response.json() | ||
|
||
# Extract bin collection dates | ||
blue_bin = result_json["features"][0]["attributes"].get("BLUE_DATE_TEXT") | ||
if blue_bin: | ||
dict_data = {"type": "Blue Bin", "collectionDate": blue_bin} | ||
bindata["bins"].append(dict_data) | ||
grey_bin = result_json["features"][0]["attributes"].get("GREY_DATE_TEXT") | ||
if grey_bin: | ||
dict_data = {"type": "Grey Bin", "collectionDate": grey_bin} | ||
bindata["bins"].append(dict_data) | ||
purple_bin = result_json["features"][0]["attributes"].get("PURPLE_DATE_TEXT") | ||
if purple_bin: | ||
dict_data = {"type": "Purple Bin", "collectionDate": purple_bin} | ||
bindata["bins"].append(dict_data) | ||
brown_bin = result_json["features"][0]["attributes"].get("BROWN_DATE_TEXT") | ||
if brown_bin: | ||
dict_data = {"type": "Brown Bin", "collectionDate": brown_bin} | ||
bindata["bins"].append(dict_data) | ||
|
||
return bindata |