Skip to content

Commit

Permalink
feat: Adding Stevenage Borough Council
Browse files Browse the repository at this point in the history
fix: #989
  • Loading branch information
m26dvd committed Nov 15, 2024
1 parent 3603117 commit 17cd12b
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,12 @@
"wiki_name": "St Albans City and District Council",
"wiki_note": "Provide your UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"StevenageBoroughCouncil": {
"uprn": "100080878852",
"url": "https://www.stevenage.gov.uk",
"wiki_name": "Stevenage Borough Council",
"wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"StHelensBC": {
"house_number": "15",
"postcode": "L34 2GA",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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")
check_uprn(uprn)
bindata = {"bins": []}

SESSION_URL = "https://stevenage-self.achieveservice.com/authapi/isauthenticated?uri=https%253A%252F%252Fstevenage-self.achieveservice.com%252Fservice%252Fmy_bin_collection_schedule&hostname=stevenage-self.achieveservice.com&withCredentials=true"
TOKEN_URL = "https://stevenage-self.achieveservice.com/apibroker/runLookup?id=5e55337a540d4"
API_URL = "https://stevenage-self.achieveservice.com/apibroker/runLookup"

data = {
"formValues": {
"Section 1": {
"token": {"value": ""},
"LLPGUPRN": {
"value": uprn,
},
"MinimumDateLookAhead": {
"value": time.strftime("%Y-%m-%d"),
},
"MaximumDateLookAhead": {
"value": str(int(time.strftime("%Y")) + 1)
+ time.strftime("-%m-%d"),
},
},
},
}

headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://stevenage-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"]

t = s.get(TOKEN_URL)
t.raise_for_status()
token_data = t.json()
data["formValues"]["Section 1"]["token"]["value"] = token_data["integration"][
"transformed"
]["rows_data"]["0"]["token"]

params = {
"id": "64ba8cee353e6",
"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")

for key in rows_data:
value = rows_data[key]
bin_type = value["bintype"].strip()

try:
date = datetime.strptime(value["collectiondate"], "%A %d %B %Y").date()
except ValueError:
continue

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

return bindata
12 changes: 12 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [South Tyneside Council](#south-tyneside-council)
- [Southwark Council](#southwark-council)
- [St Albans City and District Council](#st-albans-city-and-district-council)
- [Stevenage Borough Council](#stevenage-borough-council)
- [St Helens Borough Council](#st-helens-borough-council)
- [Stafford Borough Council](#stafford-borough-council)
- [Staffordshire Moorlands District Council](#staffordshire-moorlands-district-council)
Expand Down Expand Up @@ -2581,6 +2582,17 @@ Note: Provide your UPRN. You can find it using [FindMyAddress](https://www.findm

---

### Stevenage Borough Council
```commandline
python collect_data.py StevenageBoroughCouncil https://www.stevenage.gov.uk -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN.

---

### St Helens Borough Council
```commandline
python collect_data.py StHelensBC https://www.sthelens.gov.uk/ -s -p "XXXX XXX" -n XX -w http://HOST:PORT/
Expand Down

0 comments on commit 17cd12b

Please sign in to comment.