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:
Steffen Zimmermann
2022-12-17 14:42:30 +01:00
committed by GitHub

View File

@@ -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