mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 04:06:03 +01:00
Merge pull request #411 from mcbalston/master
Expanded search to cover next month and added garden waste as collection type
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import requests
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date, timedelta
|
||||
from bs4 import BeautifulSoup
|
||||
from waste_collection_schedule import Collection
|
||||
|
||||
@@ -15,7 +15,8 @@ SEARCH_URLS = {
|
||||
}
|
||||
COLLECTIONS = {"Household waste",
|
||||
"Mixed dry recycling (blue lidded bin)", # some addresses may not have a black box collection
|
||||
"Mixed dry recycling (blue lidded bin) and glass (black box or basket)"
|
||||
"Mixed dry recycling (blue lidded bin) and glass (black box or basket)",
|
||||
"Chargeable garden waste" # some addresses also have a chargeable garden waste collection
|
||||
}
|
||||
|
||||
|
||||
@@ -49,4 +50,29 @@ class Source:
|
||||
)
|
||||
)
|
||||
|
||||
# If current date is within 14 days of month end, also retrieve next month's dates
|
||||
futuredate = date.today() + timedelta(days=14)
|
||||
if futuredate.month != date.today().month:
|
||||
args = {
|
||||
"Postcode": self._postcode,
|
||||
"Uprn": self._uprn,
|
||||
"Month": futuredate.month,
|
||||
"Year": futuredate.year
|
||||
}
|
||||
r = session.post(SEARCH_URLS["collection_search"], params=args)
|
||||
r.raise_for_status()
|
||||
soup = BeautifulSoup(r.text, 'html.parser')
|
||||
for collection in COLLECTIONS:
|
||||
for tag in soup.find_all(
|
||||
attrs={"data-original-title": collection}
|
||||
):
|
||||
|
||||
entries.append(
|
||||
Collection(
|
||||
datetime.strptime(
|
||||
tag['data-original-datetext'], "%A %d %B, %Y").date(),
|
||||
collection,
|
||||
)
|
||||
)
|
||||
|
||||
return entries
|
||||
|
||||
Reference in New Issue
Block a user