mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
changed fetchRange to option
defaults to "month" but optinal one can choose year
This commit is contained in:
@@ -8,24 +8,27 @@ from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
TITLE = "Sector 27"
|
||||
DESCRIPTION = "Source for Muellkalender in Kreis RE."
|
||||
URL = "https://muellkalender.sector27.de/web/fetchPickups"
|
||||
TEST_CASES = {"Datteln": {"licenseKey":"DTTLN20137REKE382EHSE","cityId":"9","streetId":"2143"},
|
||||
"Marl": { "licenseKey":"MRL3102HBBUHENWIP","cityId":"3","streetId":"1055"}
|
||||
TEST_CASES = {"Datteln": {"licenseKey":"DTTLN20137REKE382EHSE","cityId":"9","streetId":"2143","fetchRange":"month"},
|
||||
"Marl": { "licenseKey":"MRL3102HBBUHENWIP","cityId":"3","streetId":"1055","fetchRange":"year"}
|
||||
}
|
||||
|
||||
class Source:
|
||||
def __init__(self, licenseKey, cityId, streetId):
|
||||
def __init__(self, licenseKey, cityId, streetId, fetchRange="month"):
|
||||
self._licenseKey = licenseKey
|
||||
self._cityId = cityId
|
||||
self._streetId = streetId
|
||||
self._range = fetchRange
|
||||
|
||||
def getviewMonthRange(self):
|
||||
|
||||
def getviewRange(self):
|
||||
now = datetime.datetime.now()
|
||||
mRange = []
|
||||
m = now.month
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
m = now.month
|
||||
y = now.year
|
||||
|
||||
# fetch 3 Month
|
||||
# fetch 3 month
|
||||
|
||||
for x in range(m,m+3):
|
||||
if x < 13:
|
||||
@@ -37,18 +40,47 @@ class Source:
|
||||
|
||||
return mRange
|
||||
|
||||
def getviewYearRange(self):
|
||||
|
||||
yRange = []
|
||||
|
||||
now = datetime.datetime.now()
|
||||
|
||||
m = now.month
|
||||
y = now.year
|
||||
|
||||
d = datetime.datetime(y,1,1,hour=12)
|
||||
|
||||
yRange.append(int(datetime.datetime.timestamp(d)))
|
||||
|
||||
# in november & december always fetch next year also
|
||||
|
||||
if m > 10:
|
||||
d = datetime.datetime(y+1,1,1,hour=12)
|
||||
|
||||
yRange.append(int(datetime.datetime.timestamp(d)))
|
||||
|
||||
return yRange
|
||||
|
||||
def fetch(self):
|
||||
args = {
|
||||
"licenseKey" : self._licenseKey,
|
||||
"cityId" : self._cityId,
|
||||
"streetId" : self._streetId
|
||||
"streetId" : self._streetId,
|
||||
}
|
||||
|
||||
args["viewrange"] = "monthRange"
|
||||
|
||||
entries = []
|
||||
|
||||
for m in self.getviewRange():
|
||||
args["viewdate"] = m
|
||||
if self._range == "month":
|
||||
fetchRange = self.getviewMonthRange()
|
||||
args["viewrange"] = "monthRange"
|
||||
else:
|
||||
fetchRange = self.getviewYearRange()
|
||||
args["viewrange"] = "yearRange"
|
||||
|
||||
for dt in fetchRange:
|
||||
|
||||
args["viewdate"] = dt
|
||||
# get json file
|
||||
r = requests.get(URL, params=args)
|
||||
|
||||
@@ -59,7 +91,7 @@ class Source:
|
||||
type = data["pickups"][d][0]["label"]
|
||||
|
||||
pickupdate = datetime.date.fromtimestamp(int(d))
|
||||
|
||||
|
||||
entries.append(Collection(pickupdate, type))
|
||||
|
||||
|
||||
return entries
|
||||
@@ -14,6 +14,7 @@ waste_collection_schedule:
|
||||
licenseKey: VALIDKEY
|
||||
cityId: CITYID
|
||||
streetId: STREETID
|
||||
fetchRange: FETCHRANGE
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
@@ -27,6 +28,11 @@ waste_collection_schedule:
|
||||
**STREETID**<br>
|
||||
*(string) (required)*
|
||||
|
||||
**FETCHRANGE**<br>
|
||||
*(string) (optional)* default: month or year
|
||||
|
||||
The `fetchRange` limits the query count to the server. "Month" does three queries, "year" usually one, only in nov/dec it does two.
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
@@ -37,6 +43,7 @@ waste_collection_schedule:
|
||||
licenseKey: Dattelnx2345612
|
||||
cityId: 9
|
||||
streetId: 2162
|
||||
fetchRange: year
|
||||
```
|
||||
|
||||
## How to get the source arguments
|
||||
|
||||
Reference in New Issue
Block a user