mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 00:04:11 +01:00
address arg implemented
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import re
|
||||
import requests
|
||||
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from datetime import datetime
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
@@ -12,6 +14,7 @@ TEST_CASES = {
|
||||
"Test_001": {"house_number": "6", "street": "Withypitts", "postcode": "RH10 4PJ"},
|
||||
"Test_002": {"house_name": "Oaklands", "street": "Oaklands Road", "postcode": "RH16 1SS"},
|
||||
"Test_003": {"house_number": 9, "street": "Bolnore Road", "postcode": "RH16 4AB"},
|
||||
"Test_004": {"address": "HAZELMERE REST HOME, 21 BOLNORE ROAD RH16 4AB"}
|
||||
}
|
||||
|
||||
ICON_MAP = {
|
||||
@@ -21,25 +24,30 @@ ICON_MAP = {
|
||||
}
|
||||
|
||||
API_URL = "https://www.midsussex.gov.uk/waste-recycling/bin-collection/"
|
||||
REGEX = "([A-Z]{1,2}\d[A-Z\d]?\s*\d[A-Z]{2})" # regex for UK postcode format
|
||||
|
||||
class Source:
|
||||
def __init__(self, house_name="", house_number="", street="", postcode=""):
|
||||
def __init__(self, house_name="", house_number="", street="", postcode="", address=""):
|
||||
self._house_name = str(house_name).upper()
|
||||
self._house_number = str(house_number)
|
||||
self._street = str(street).upper()
|
||||
self._postcode = str(postcode).upper()
|
||||
self._address = str(address).upper()
|
||||
|
||||
def fetch(self):
|
||||
s = requests.Session()
|
||||
|
||||
if self._house_name == "":
|
||||
address = self._house_number + " " + self._street + " " + self._postcode
|
||||
if self._address != "":
|
||||
# extract postcode
|
||||
self._postcode = re.findall(REGEX, self._address)
|
||||
elif self._house_name == "":
|
||||
self._address = self._house_number + " " + self._street + " " + self._postcode
|
||||
else:
|
||||
address = self._house_name + "," + self._house_number + " " + self._street + " " + self._postcode
|
||||
self._address = self._house_name + "," + self._house_number + " " + self._street + " " + self._postcode
|
||||
|
||||
payload = {
|
||||
"PostCodeStep.strAddressSearch": self._postcode,
|
||||
"AddressStep.strAddressSelect": address,
|
||||
"AddressStep.strAddressSelect": self._address,
|
||||
"Next": "true",
|
||||
"StepIndex": "1",
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
args:
|
||||
address: ADDRESS
|
||||
house_name: NAME
|
||||
house_number: NUMBER
|
||||
street: STREET
|
||||
@@ -17,6 +18,16 @@ waste_collection_schedule:
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
#### Preferred Method
|
||||
**address**
|
||||
*(string) (required)*
|
||||
|
||||
The address as it appears on the midsussex.gov.uk website.
|
||||
|
||||
This is the preferred approach, if this is not used then the following legacy methods can be used.
|
||||
|
||||
#### Legacy Methods
|
||||
|
||||
**house_name**
|
||||
*(string) (optional)*
|
||||
|
||||
@@ -34,6 +45,16 @@ If house_name is not provided then house_number becomes *(required)*
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
# Preferred method
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
args:
|
||||
address: HAZELMERE REST HOME, 21 BOLNORE ROAD RH16 4AB
|
||||
```
|
||||
|
||||
```yaml
|
||||
# legacy method: house name, but no house number
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
@@ -44,6 +65,7 @@ waste_collection_schedule:
|
||||
```
|
||||
|
||||
```yaml
|
||||
# legacy method: house number, but no house name
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
@@ -53,6 +75,29 @@ waste_collection_schedule:
|
||||
postcode: RH10 4PJ
|
||||
```
|
||||
|
||||
```yaml
|
||||
# legacy method: house name used instead of house number
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
args:
|
||||
house_number: Lamedos
|
||||
street: Withypitts
|
||||
postcode: RH11 4XY
|
||||
```
|
||||
```yaml
|
||||
|
||||
# legacy method: house name and house number
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: midsussex_gov_uk
|
||||
args:
|
||||
house_name: Tireggub
|
||||
house_number: Lamedos
|
||||
street: Widdershins
|
||||
postcode: RH14 8BX
|
||||
```
|
||||
|
||||
## How to get the source arguments
|
||||
|
||||
Search for your collection schedule on the address on the [Mid-Sussex District Council](https://www.midsussex.gov.uk/waste-recycling/bin-collection/) site to see how they format your address. General rule seems to be `HOUSE_NAME, HOUSE_NUMBER STREET POSTCODE` but it can vary for multi-occupancy buildings etc, so you may need to adjust which parts of the address are used for each arg.
|
||||
Search for your collection schedule on the address on the [Mid-Sussex District Council](https://www.midsussex.gov.uk/waste-recycling/bin-collection/) site to see how they format your address. Preferred approach is to copy the address as displayed. If that doesn't work, the individual components can be supplied. General rule seems to be `HOUSE_NAME, HOUSE_NUMBER STREET POSTCODE` but it can vary for multi-occupancy buildings, house names where there are no numbers, house names where there are also house numbers, etc, so you may need to adjust which parts of the address are used for each arg.
|
||||
Reference in New Issue
Block a user