Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Council Pack 6 #896

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@
"wiki_name": "Dover District Council",
"wiki_note": "Replace XXXXXXXXXXXX with your UPRN. To get the UPRN, you can use [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"DudleyCouncil": {
"url": "https://my.dudley.gov.uk",
"wiki_command_url_override": "https://my.dudley.gov.uk",
"uprn": "90014244",
"wiki_name": "Dudley Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"DurhamCouncil": {
"skip_get_url": true,
"uprn": "200003218818",
Expand Down Expand Up @@ -860,6 +867,13 @@
"url": "https://www.northyorks.gov.uk/bin-calendar/lookup",
"wiki_name": "North Yorkshire Council"
},
"NorwichCityCouncil": {
"url": "https://www.norwich.gov.uk",
"wiki_command_url_override": "https://www.norwich.gov.uk",
"uprn": "100090888980",
"wiki_name": "Norwich City Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"NorthumberlandCouncil": {
"house_number": "22",
"postcode": "NE46 1UQ",
Expand All @@ -886,6 +900,13 @@
"wiki_name": "Perth and Kinross Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"PlymouthCouncil": {
"url": "https://www.plymouth.gov.uk",
"wiki_command_url_override": "https://www.plymouth.gov.uk",
"uprn": "100040420582",
"wiki_name": "Plymouth Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"PortsmouthCityCouncil": {
"postcode": "PO4 0LE",
"skip_get_url": true,
Expand Down Expand Up @@ -1065,6 +1086,13 @@
"url": "https://www.southoxon.gov.uk/south-oxfordshire-district-council/recycling-rubbish-and-waste/when-is-your-collection-day/",
"wiki_name": "South Oxfordshire Council"
},
"SouthRibbleCouncil": {
"url": "https://www.southribble.gov.uk",
"wiki_command_url_override": "https://www.southribble.gov.uk",
"uprn": "010013246384",
"wiki_name": "South Ribble Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"SouthTynesideCouncil": {
"house_number": "1",
"postcode": "NE33 3JW",
Expand Down
81 changes: 81 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/DudleyCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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": []}

SESSION_URL = "https://my.dudley.gov.uk/authapi/isauthenticated?uri=https%253A%252F%252Fmy.dudley.gov.uk%252Fen%252FAchieveForms%252F%253Fform_uri%253Dsandbox-publish%253A%252F%252FAF-Process-373f5628-9aae-4e9e-ae09-ea7cd0588201%252FAF-Stage-52ec040b-10e6-440f-b964-23f924741496%252Fdefinition.json%2526redirectlink%253D%25252Fen%2526cancelRedirectLink%253D%25252Fen%2526consentMessage%253Dyes&hostname=my.dudley.gov.uk&withCredentials=true"

API_URL = "https://my.dudley.gov.uk/apibroker/runLookup"

data = {
"formValues": {
"My bins": {
"uprnToCheck": {"value": user_uprn},
}
},
}

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://my.dudley.gov.uk/fillform/?iframe_id=fillform-frame-1&db_id=",
}
s = requests.session()
r = s.get(SESSION_URL)
r.raise_for_status()
session_data = r.json()
sid = session_data["auth-session"]
params = {
"id": "64899d4c2574c",
"repeat_against": "",
"noRetry": "true",
"getOnlyTokens": "undefined",
"log_id": "",
"app_name": "AF-Renderer::Self",
# unix_timestamp
"_": str(int(time.time() * 1000)),
"sid": sid,
}
r = s.post(API_URL, json=data, headers=headers, params=params)
r.raise_for_status()
data = r.json()
rows_data = data["integration"]["transformed"]["rows_data"]["0"]
if not isinstance(rows_data, dict):
raise ValueError("Invalid data returned from API")
BIN_TYPES = [
("refuseDate", "Refuse"),
("recyclingDate", "Recycling"),
("gardenDate", "Garden Waste"),
]
bin_type_dict = dict(BIN_TYPES)

for row in rows_data.items():
if (row[0].endswith("Date")) and not row[0].endswith("EndDate"):
if row[1]:
bin_type = bin_type_dict.get(row[0], row[0])
collection_date = datetime.strptime(row[1], "%Y-%m-%d").strftime(
"%d/%m/%Y"
)
dict_data = {"type": bin_type, "collectionDate": collection_date}
bindata["bins"].append(dict_data)

return bindata
75 changes: 75 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/NorwichCityCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import time

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


# 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": []}

API_URL = "https://maps.norwich.gov.uk/arcgis/rest/services/MyNorwich/PropertyDetails/FeatureServer/2/query"

params = {
"f": "json",
"where": f"UPRN='{user_uprn}' or UPRN='0{user_uprn}'",
"returnGeometry": "true",
"spatialRel": "esriSpatialRelIntersects",
"geometryType": "esriGeometryPolygon",
"inSR": "4326",
"outFields": "*",
"outSR": "4326",
"resultRecordCount": "1000",
}

r = requests.get(API_URL, params=params)

data = r.json()
data = data["features"][0]["attributes"]["WasteCollectionHtml"]
soup = BeautifulSoup(data, "html.parser")

alternateCheck = soup.find("p")
if alternateCheck.text.__contains__("alternate"):
alternateCheck = True
else:
alternateCheck = False

strong = soup.find_all("strong")

if alternateCheck:
bin_types = strong[2].text.strip().replace(".", "").split(" and ")
for bin in bin_types:
dict_data = {
"type": bin,
"collectionDate": strong[1].text.strip(),
}
bindata["bins"].append(dict_data)
else:
p_tag = soup.find_all("p")
i = 1
for p in p_tag:
bin_types = (
p.text.split("Your ")[1].split(" is collected")[0].split(" and ")
)
for bin in bin_types:
dict_data = {
"type": bin,
"collectionDate": strong[i].text.strip(),
}
bindata["bins"].append(dict_data)
i += 2

return bindata
81 changes: 81 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/PlymouthCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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": []}

SESSION_URL = "https://plymouth-self.achieveservice.com/authapi/isauthenticated?uri=https%253A%252F%252Fplymouth-self.achieveservice.com%252Fen%252FAchieveForms%252F%253Fform_uri%253Dsandbox-publish%253A%252F%252FAF-Process-31283f9a-3ae7-4225-af71-bf3884e0ac1b%252FAF-Stagedba4a7d5-e916-46b6-abdb-643d38bec875%252Fdefinition.json%2526redirectlink%253D%25252Fen%2526cancelRedirectLink%253D%25252Fen%2526consentMessage%253Dyes&hostname=plymouth-self.achieveservice.com&withCredentials=true"

API_URL = "https://plymouth-self.achieveservice.com/apibroker/runLookup"

data = {
"formValues": {
"Section 1": {
"number1": {"value": user_uprn},
"lastncoll": {"value": "0"},
"nextncoll": {"value": "9"},
}
},
}

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://plymouth-self.achieveservice.com/fillform/?iframe_id=fillform-frame-1&db_id=",
}
s = requests.session()
r = s.get(SESSION_URL)
r.raise_for_status()
session_data = r.json()
sid = session_data["auth-session"]
params = {
"id": "5c99439d85f83",
"repeat_against": "",
"noRetry": "false",
"getOnlyTokens": "undefined",
"log_id": "",
"app_name": "AF-Renderer::Self",
# unix_timestamp
"_": str(int(time.time() * 1000)),
"sid": sid,
}
r = s.post(API_URL, json=data, headers=headers, params=params)
r.raise_for_status()
data = r.json()
rows_data = data["integration"]["transformed"]["rows_data"]
if not isinstance(rows_data, dict):
raise ValueError("Invalid data returned from API")
BIN_TYPES = [
("OR", "Garden Waste Bin"),
("DO", "Brown Domestic Bin"),
("RE", "Green Recycling Bin"),
]
bin_type_dict = dict(BIN_TYPES)

for row in rows_data.items():
bin_type = bin_type_dict.get(row[1]["Round_Type"], row[1]["Round_Type"])
collection_date = datetime.strptime(
row[1]["Date"].split("T")[0], "%Y-%m-%d"
).strftime("%d/%m/%Y")
dict_data = {"type": bin_type, "collectionDate": collection_date}
bindata["bins"].append(dict_data)

return bindata
83 changes: 83 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/SouthRibbleCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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": []}

SESSION_URL = "https://southribble-ss.achieveservice.com/authapi/isauthenticated?uri=https%253A%252F%252Fsouthribble-ss.achieveservice.com%252FAchieveForms%252F%253Fmode%253Dfill%2526form_uri%253Dsandbox-publish%25253A%252F%252FAF-Process-d3971054-2e93-4a74-8375-494347dd13fd%252FAF-Stage-2693df73-8a5f-4e24-86b8-456ef81dd4a1%252Fdefinition.json%2526process%253D1%2526process_uri%253Dsandbox-processes%25253A%252F%252FAF-Process-d3971054-2e93-4a74-8375-494347dd13fd%2526process_id%253DAF-Process-d3971054-2e93-4a74-8375-494347dd13fd%2526accept%253Dyes%2526consentMessageIds%25255B%25255D%253D3%2526accept%253Dyes%2526consentMessageIds%255B%255D%253D3&hostname=southribble-ss.achieveservice.com&withCredentials=true"

API_URL = "https://southribble-ss.achieveservice.com/apibroker/runLookup"

data = {
"formValues": {
"Your Collections": {
"PickupDate": {"value": datetime.now().strftime("%Y-%m-%d")},
},
"Your details": {
"LLPGUPRN": {"value": user_uprn},
},
},
}

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://southribble-ss.achieveservice.com/fillform/?iframe_id=fillform-frame-1&db_id=",
}
s = requests.session()
r = s.get(SESSION_URL)
r.raise_for_status()
session_data = r.json()
sid = session_data["auth-session"]
params = {
"id": "58ab44ef078bd",
"repeat_against": "",
"noRetry": "false",
"getOnlyTokens": "undefined",
"log_id": "",
"app_name": "AF-Renderer::Self",
# unix_timestamp
"_": str(int(time.time() * 1000)),
"sid": sid,
}
r = s.post(API_URL, json=data, headers=headers, params=params)
r.raise_for_status()
data = r.json()
rows_data = data["integration"]["transformed"]["rows_data"]["0"]
if not isinstance(rows_data, dict):
raise ValueError("Invalid data returned from API")
BIN_TYPES = [
("RCNextCollectionDate", "Household Waste (Non-Recyclable Waste)"),
("RENextCollectionDate", "Blue/Green Recyclable Waste"),
("GWNextCollectionDate", "Garden Waste Collection"),
("FWNextCollectionDate", "Food Waste"),
]
bin_type_dict = dict(BIN_TYPES)

for row in rows_data.items():
if row[0].endswith("NextCollectionDate"):
if row[1]:
bin_type = bin_type_dict.get(row[0], row[0])
collection_date = row[1]
dict_data = {"type": bin_type, "collectionDate": collection_date}
bindata["bins"].append(dict_data)

return bindata
Loading