Skip to content

Commit 44bc529

Browse files
committed
fix(OxfordCityCouncil): Fixed Oxford City Council parsing dues to changes in output from the website
1 parent 2051201 commit 44bc529

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

uk_bin_collection/tests/input.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,8 +1828,8 @@
18281828
"OxfordCityCouncil": {
18291829
"postcode": "OX3 7QF",
18301830
"uprn": "100120820551",
1831-
"url": "https://www.oxford.gov.uk",
1832-
"wiki_command_url_override": "https://www.oxford.gov.uk",
1831+
"url": "https://www.oxford.gov.uk/xfp/form/142",
1832+
"wiki_command_url_override": "https://www.oxford.gov.uk/xfp/form/142",
18331833
"wiki_name": "Oxford",
18341834
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.",
18351835
"LAD24CD": "E07000178"

uk_bin_collection/uk_bin_collection/councils/OxfordCityCouncil.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def parse_data(self, page: str, **kwargs) -> dict:
2121
check_postcode(user_postcode)
2222
bindata = {"bins": []}
2323

24-
session_uri = "https://www.oxford.gov.uk/mybinday"
25-
URI = "https://www.oxford.gov.uk/xfp/form/142"
24+
session_uri = "https://www.oxford.gov.uk/xfp/form/142"
25+
URI = "https://www.oxford.gov.uk/xfp/form/142#q6ad4e3bf432c83230a0347a6eea6c805c672efeb_0"
2626

2727
session = requests.Session()
2828
token_response = session.get(session_uri)
@@ -40,15 +40,18 @@ def parse_data(self, page: str, **kwargs) -> dict:
4040

4141
collection_response = session.post(URI, data=form_data)
4242

43-
collection_soup = BeautifulSoup(collection_response.text, "html.parser")
44-
for paragraph in collection_soup.find("div", class_="editor").find_all("p"):
45-
matches = re.match(r"^(\w+) Next Collection: (.*)", paragraph.text)
43+
soup = BeautifulSoup(collection_response.text, "html.parser")
44+
#print(soup)
45+
46+
for paragraph in soup.find("div", class_="editor").find_all("p"):
47+
matches = re.match(r"^Your next (\w+) collections: (.*)", paragraph.text)
4648
if matches:
4749
collection_type, date_string = matches.groups()
50+
parts = date_string.split(', ', 1)
4851
try:
49-
date = datetime.strptime(date_string, "%A %d %B %Y").date()
52+
date = datetime.strptime(parts[0], "%A %d %B %Y").date()
5053
except ValueError:
51-
date = datetime.strptime(date_string, "%A %d %b %Y").date()
54+
date = datetime.strptime(parts[0], "%A %d %b %Y").date()
5255

5356
dict_data = {
5457
"type": collection_type,
@@ -61,3 +64,5 @@ def parse_data(self, page: str, **kwargs) -> dict:
6164
)
6265

6366
return bindata
67+
68+

wiki/Councils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,7 @@ Note: Replace UPRN in URL with your own UPRN.
26822682

26832683
### Oxford City Council
26842684
```commandline
2685-
python collect_data.py OxfordCityCouncil https://www.oxford.gov.uk -u XXXXXXXX -p "XXXX XXX"
2685+
python collect_data.py OxfordCityCouncil https://www.oxford.gov.uk/xfp/form/142 -u XXXXXXXX -p "XXXX XXX"
26862686
```
26872687
Additional parameters:
26882688
- `-u` - UPRN

0 commit comments

Comments
 (0)