Skip to content

Commit

Permalink
add source milton_keynes_gov_uk
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Aug 27, 2023
1 parent 19d2209 commit f82661a
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ Waste collection schedules in the following formats and countries are supported.
- [Mendip District Council](/doc/source/iweb_itouchvision_com.md) / somerset.gov.uk
- [Mid-Sussex District Council](/doc/source/midsussex_gov_uk.md) / midsussex.gov.uk
- [Middlesbrough Council](/doc/source/middlesbrough_gov_uk.md) / middlesbrough.gov.uk
- [Milton Keynes council](/doc/source/milton_keynes_gov_uk.md) / milton-keynes.gov.uk
- [Newcastle City Council](/doc/source/newcastle_gov_uk.md) / community.newcastle.gov.uk
- [Newcastle Under Lyme Borough Council](/doc/source/newcastle_staffs_gov_uk.md) / newcastle-staffs.gov.uk
- [Newport City Council](/doc/source/newport_gov_uk.md) / newport.gov.uk
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# modified version of bexley_gov_uk.py

from datetime import datetime
from time import time_ns

import requests
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Milton Keynes council"
DESCRIPTION = "Source for Milton Keynes council."
URL = "milton-keynes.gov.uk"
TEST_CASES = {
"North Row, Central": {"uprn": 25032037},
"Adelphi Street, Campbell Park": {"uprn": 25044504},
}


ICON_MAP = {
"REFUSE": "mdi:trash-can",
"RECYCLE": "mdi:recycle",
"RECYCLING": "mdi:recycle",
"FOOD": "mdi:leaf",
"GARDEN": "mdi:leaf",
}


SITE_URL = (
"https://mycouncil.milton-keynes.gov.uk/service/Waste_Collection_Round_Checker"
)
HEADERS = {
"user-agent": "Mozilla/5.0",
}


class Source:
def __init__(self, uprn: str | int):
self._uprn: str = str(uprn)

def fetch(self):
s = requests.Session()

# Set up session
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
s.get(
"https://mycouncil.milton-keynes.gov.uk/apibroker/domain/mycouncil.milton-keynes.gov.uk",
params={
"_": timestamp,
},
headers=HEADERS,
)

# This request gets the session ID
sid_request = s.get(
"https://mycouncil.milton-keynes.gov.uk/authapi/isauthenticated",
params={
"uri": "https://mycouncil.milton-keynes.gov.uk/service/Waste_Collection_Round_Checker",
"hostname": "mycouncil.milton-keynes.gov.uk",
"withCredentials": "true",
},
)
sid_data = sid_request.json()
sid = sid_data["auth-session"]

# This request retrieves the schedule
timestamp = time_ns() // 1_000_000 # epoch time in milliseconds
payload = {"formValues": {"Section 1": {"uprnCore": {"value": self._uprn}}}}
schedule_request = s.post(
"https://mycouncil.milton-keynes.gov.uk/apibroker/runLookup",
headers=HEADERS,
params={
# "id": "61320b2acf8a3",
"id": "64d9feda3a507",
"repeat_against": "",
"noRetry": "false",
"getOnlyTokens": "undefined",
"log_id": "",
"app_name": "AF-Renderer::Self",
"_": str(timestamp),
"sid": str(sid),
},
json=payload,
)

rowdata = schedule_request.json()["integration"]["transformed"]["rows_data"]

# Extract bin types and next collection dates
entries = []
for index, item in rowdata.items():
# print(item)
bin_type = item["AssetTypeName"]
icon = None

for key, icon_name in ICON_MAP.items():
if (
key in item["AssetTypeName"].upper()
or key in item["TaskTypeName"].upper()
or key in item["ServiceName"].upper()
):
icon = icon_name
break

dates = [
datetime.strptime(item["NextInstance"], "%Y-%m-%d").date(),
datetime.strptime(item["LastInstance"], "%Y-%m-%d").date(),
]
for date in dates:
entries.append(
Collection(t=bin_type, date=date, icon=icon),
)
return entries
34 changes: 34 additions & 0 deletions doc/source/milton_keynes_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Milton Keynes council

Support for schedules provided by [Milton Keynes council](milton-keynes.gov.uk), serving Milton Keynes, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: milton_keynes_gov_uk
args:
uprn: "UPRN"

```
### Configuration Variables
**uprn**
*(String | Integer) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: milton_keynes_gov_uk
args:
uprn: "25032037"

```
## How to get the source argument
An easy way to discover your Unique Property Reference Number (UPRN) is by going to <https://www.findmyaddress.co.uk/> and entering in your address details.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Waste collection schedules from service provider web sites are updated daily, de
| Slovenia | Moji odpadki, Ljubljana |
| Sweden | Affärsverken, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, Uppsala Vatten och Avfall AB, VA Syd Sophämntning |
| Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden |
| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council |
| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council |
| United States of America | Albuquerque, New Mexico, USA, City of Bloomington, City of Cambridge, City of Gastonia, NC, City of Georgetown, TX, City of Oklahoma City, City of Pittsburgh, Louisville, Kentucky, USA, Newark, Delaware, USA, Olympia, Washington, USA, ReCollect, Recycle Coach, Republic Services, Seattle Public Utilities, Tucson, Arizona, USA |
<!--End of country section-->

Expand Down

0 comments on commit f82661a

Please sign in to comment.