refactor binzone_uk

This commit is contained in:
mampfes
2023-03-10 07:29:21 +01:00
parent a02939398b
commit 3f9ac22a6e
2 changed files with 25 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
import logging
import requests
import requests
from bs4 import BeautifulSoup
from dateutil.parser import parse
from waste_collection_schedule import Collection
@@ -9,23 +9,21 @@ TITLE = "Binzone"
URL = "https://www.southoxon.gov.uk/"
EXTRA_INFO = [
{
"title": "South Oxfordshire District Council",
"url": "https://www.southoxon.gov.uk/"
"title": "South Oxfordshire District Council",
"url": "https://www.southoxon.gov.uk/",
},
{
"title": "Vale of White Horse District Council",
"url": "https://www.whitehorsedc.gov.uk/"
"title": "Vale of White Horse District Council",
"url": "https://www.whitehorsedc.gov.uk/",
},
]
DESCRIPTION = (
"""Consolidated source for waste collection services from:
DESCRIPTION = """Consolidated source for waste collection services from:
South Oxfordshire District Council
Vale of White Horse District Council
"""
)
TEST_CASES = {
"VOWH" : {"uprn": "100120903018"},
"SO" : {"uprn": "100120883950"},
"VOWH": {"uprn": "100120903018"},
"SO": {"uprn": "100120883950"},
}
ICON_MAP = {
@@ -34,7 +32,7 @@ ICON_MAP = {
"GARDEN WASTE": "mdi:leaf",
"SMALL ELECTRICAL ITEMS": "mdi:hair-dryer",
"FOOD BIN": "mdi:food-apple",
"TEXTILES": "mdi:hanger"
"TEXTILES": "mdi:hanger",
}
@@ -42,7 +40,7 @@ _LOGGER = logging.getLogger(__name__)
class Source:
def __init__(self, uprn=None):
def __init__(self, uprn):
self._uprn = uprn
def fetch(self):
@@ -53,35 +51,22 @@ class Source:
# as a reference. This works for both councils, using the same url.
# UPRN is passed in via a cookie. Set cookies/params and GET the page
cookies = {
'SVBINZONE': f'SOUTH%3AUPRN%40{self._uprn}',
}
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8',
'Accept-Language': 'en-GB,en;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Referer': 'https://eform.southoxon.gov.uk/ebase/BINZONE_DESKTOP.eb?SOVA_TAG=SOUTH&ebd=0&ebz=1_1668467255368',
'Sec-Fetch-Dest': 'document',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Sec-GPC': '1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
"SVBINZONE": f"SOUTH%3AUPRN%40{self._uprn}",
}
params = {
'SOVA_TAG': 'SOUTH',
'ebd': '0',
"SOVA_TAG": "SOUTH",
"ebd": "0",
}
if self._uprn:
# GET request returns schedule for matching uprn
r = s.get('https://eform.southoxon.gov.uk/ebase/BINZONE_DESKTOP.eb', params=params,
headers=headers, cookies=cookies)
responseContent = r.text
else:
raise Exception("Address not found")
# GET request returns schedule for matching uprn
r = s.get(
"https://eform.southoxon.gov.uk/ebase/BINZONE_DESKTOP.eb",
params=params,
cookies=cookies,
)
r.raise_for_status()
responseContent = r.text
entries = []
@@ -102,9 +87,9 @@ class Source:
if round_type in bin_type.upper():
entries.append(
Collection(
date = parse(bin_date).date(),
t = round_type,
icon = ICON_MAP.get(round_type)
date=parse(bin_date).date(),
t=round_type,
icon=ICON_MAP.get(round_type),
)
)

View File

@@ -19,7 +19,6 @@ waste_collection_schedule:
This is required to unambiguously identify the property.
## Example
```yaml