From 3a80852c922f87023fab97621fab2f3e90fcc32c Mon Sep 17 00:00:00 2001 From: dt215git <86194065+dt215git@users.noreply.github.com> Date: Sun, 19 Mar 2023 20:01:39 +0000 Subject: [PATCH] tidy-up --- .../source/wigan_gov_uk.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/wigan_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wigan_gov_uk.py index e7e91aff..3069827f 100644 --- a/custom_components/waste_collection_schedule/waste_collection_schedule/source/wigan_gov_uk.py +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wigan_gov_uk.py @@ -15,7 +15,7 @@ URL = "https://wigan.gov.uk" TEST_CASES = { "Test_001": {"postcode": "WN5 9BH", "uprn": "100011821616"}, - "Test_002": {"postcode": "WN6 8RG", "uprn": "100011776568"}, + "Test_002": {"postcode": "WN6 8RG", "uprn": "100011776859"}, "Test_003": {"postcode": "wn36au", "uprn": 100011749007}, } @@ -29,10 +29,9 @@ ICON_MAP = { REGEX_ORDINALS = r"(st|nd|rd|th)" - class Source: def __init__(self, postcode, uprn): - self._postcode = str(postcode.upper().strip()) + self._postcode = str(postcode.upper()) self._uprn = str(uprn).zfill(12) def get_asp_var(self, broth, id) -> str: @@ -40,16 +39,17 @@ class Source: return asp_var def fetch(self): - # Initial a session to generate required ASP variables + + # Initiate a session to generate required ASP variables s= requests.Session() r0 = s.get("https://apps.wigan.gov.uk/MyNeighbourhood/") soup = BeautifulSoup(r0.text, "html.parser") # Build initial search payload payload = { - "__VIEWSTATE": get_asp_var(soup, "__VIEWSTATE"), - "__VIEWSTATEGENERATOR": get_asp_var(soup, "__VIEWSTATEGENERATOR"), - "__EVENTVALIDATION": get_asp_var(soup, "__EVENTVALIDATION"), + "__VIEWSTATE": self.get_asp_var(soup, "__VIEWSTATE"), + "__VIEWSTATEGENERATOR": self.get_asp_var(soup, "__VIEWSTATEGENERATOR"), + "__EVENTVALIDATION": self.get_asp_var(soup, "__EVENTVALIDATION"), "ctl00$ContentPlaceHolder1$txtPostcode": self._postcode, "ctl00$ContentPlaceHolder1$btnPostcodeSearch": "Search", } @@ -63,9 +63,9 @@ class Source: "__EVENTTARGET": "ctl00$ContentPlaceHolder1$lstAddresses", "__EVENTARGUMENT": "", "__LASTFOCUS": "", - "__VIEWSTATE": get_asp_var(soup, "__VIEWSTATE"), - "__VIEWSTATEGENERATOR": get_asp_var(soup, "__VIEWSTATEGENERATOR"), - "__EVENTVALIDATION": get_asp_var(soup, "__EVENTVALIDATION"), + "__VIEWSTATE": self.get_asp_var(soup, "__VIEWSTATE"), + "__VIEWSTATEGENERATOR": self.get_asp_var(soup, "__VIEWSTATEGENERATOR"), + "__EVENTVALIDATION": self.get_asp_var(soup, "__EVENTVALIDATION"), "ctl00$ContentPlaceHolder1$txtPostcode": self._postcode, "ctl00$ContentPlaceHolder1$lstAddresses": "UPRN" + self._uprn, } @@ -76,7 +76,6 @@ class Source: # Extract the collection schedules bin_collections = soup.findAll("div", {"class": "BinsRecycling"}) - entries = [] for bin in bin_collections: waste_type = bin.find("h2").text