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: Adding Horsham District Council #1069

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 9 additions & 1 deletion uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,14 @@
"wiki_name": "Hinckley and Bosworth Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"HorshamDistrictCouncil": {
"house_number": "Horsham District Council, RH12 1HQ",
"skip_get_url": true,
"uprn": "200004781462",
"url": "https://horsham.moderngov.co.uk/",
"wiki_name": "Horsham District Council",
"wiki_note": "Horsham needs to be passed both a UPRN and a USRN to work. Find these on [FindMyAddress](https://www.findmyaddress.co.uk/search) or [FindMyStreet](https://www.findmystreet.co.uk/map)."
},
"HounslowCouncil": {
"house_number": "17A LAMPTON PARK ROAD, HOUNSLOW",
"postcode": "TW3 4HS",
Expand Down Expand Up @@ -2120,4 +2128,4 @@
"wiki_name": "York Council",
"wiki_note": "Provide your UPRN."
}
}
}
112 changes: 112 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/HorshamDistrictCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import time

import requests
from dateutil.relativedelta import relativedelta

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:
# Make a BS4 object
uprn = kwargs.get("uprn")
usrn = kwargs.get("paon")
check_uprn(uprn)
check_usrn(usrn)
bindata = {"bins": []}

SESSION_URL = "https://horshamdc-self.achieveservice.com/authapi/isauthenticated?uri=https%253A%252F%252Fhorshamdc-self.achieveservice.com%252Fen%252FAchieveForms%252F%253Fform_uri%253Dsandbox-publish%253A%252F%252FAF-Process-fb73f73e-e8f5-4441-9f83-8b5d04d889d6%252FAF-Stage-ec9ada91-d2d9-43bc-9730-597d15fc8108%252Fdefinition.json%2526redirectlink%253D%252Fen%2526cancelRedirectLink%253D%252Fen%2526noLoginPrompt%253D1%2526accept%253Dyes&hostname=horshamdc-self.achieveservice.com&withCredentials=true"

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

currentdate = datetime.now().strftime("%d/%m/%Y")

data = {
"formValues": {
"Address": {
"address": {
"value": {
"Address": {
"usrn": {
"value": usrn,
},
"uprn": {
"value": uprn,
},
}
},
},
"dayConverted": {
"value": currentdate,
},
"getCollection": {
"value": "true",
},
"getWorksheets": {
"value": "false",
},
},
},
}

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://horshamdc-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 = {
"api": "RunLookup",
"id": "5b4f0ec5f13f4",
"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")

# Extract each service's relevant details for the bin schedule
for key, value in rows_data.items():
if key.endswith("DateNext"):
BinType = key.replace("DateNext", "Service")
for key2, value2 in rows_data.items():
if key2 == BinType:
BinType = value2
next_collection = datetime.strptime(value, "%A %d %B").replace(
year=datetime.now().year
)
if datetime.now().month == 12 and next_collection.month == 1:
next_collection = next_collection + relativedelta(years=1)

dict_data = {
"type": BinType,
"collectionDate": next_collection.strftime(date_format),
}
bindata["bins"].append(dict_data)

return bindata
14 changes: 14 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Highland Council](#highland-council)
- [High Peak Council](#high-peak-council)
- [Hinckley and Bosworth Borough Council](#hinckley-and-bosworth-borough-council)
- [Horsham District Council](#horsham-district-council)
- [Hounslow Council](#hounslow-council)
- [Hull City Council](#hull-city-council)
- [Huntingdon District Council](#huntingdon-district-council)
Expand Down Expand Up @@ -1635,6 +1636,19 @@ Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/searc

---

### Horsham District Council
```commandline
python collect_data.py HorshamDistrictCouncil https://horsham.moderngov.co.uk/ -s -u XXXXXXXX -n XX
```
Additional parameters:
- `-s` - skip get URL
- `-u` - UPRN
- `-n` - house number

Note: Horsham needs to be passed both a UPRN and a USRN to work. Find these on [FindMyAddress](https://www.findmyaddress.co.uk/search) or [FindMyStreet](https://www.findmystreet.co.uk/map).

---

### Hounslow Council
```commandline
python collect_data.py HounslowCouncil https://www.hounslow.gov.uk/info/20272/recycling_and_waste_collection_day_finder -s -u XXXXXXXX -p "XXXX XXX" -n XX -w http://HOST:PORT/
Expand Down
Loading