-
-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from mampfes/was_wolfsburg_de
add source WAS-Wolfsburg.de
- Loading branch information
Showing
4 changed files
with
98 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...components/waste_collection_schedule/waste_collection_schedule/source/was_wolfsburg_de.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import datetime | ||
import re | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
from waste_collection_schedule.service.ICS import ICS | ||
|
||
TITLE = "Wolfsburger Abfallwirtschaft und Straßenreinigung" | ||
DESCRIPTION = "Source for waste collections for WAS-Wolfsburg, Germany." | ||
URL = "https://was-wolfsburg.de" | ||
TEST_CASES = {"WAS": {"city": "Barnstorf", "street": "Bahnhofspassage"}} | ||
|
||
|
||
class Source: | ||
def __init__(self, city, street): | ||
self._city = city | ||
self._street = street | ||
self._ics = ICS() | ||
|
||
def fetch(self): | ||
# fetch "Gelber Sack" | ||
args = {"g": self._city} | ||
r = requests.get( | ||
"https://was-wolfsburg.de/subgelberweihgarten/php/abfuhrgelber.php", | ||
params=args, | ||
) | ||
|
||
entries = [] | ||
match = re.findall(r"(\d{2})\.(\d{2})\.(\d{4})", r.text) | ||
for m in match: | ||
date = datetime.date(day=int(m[0]), month=int(m[1]), year=int(m[2])) | ||
entries.append(Collection(date, "Gelber Sack")) | ||
|
||
# fetch remaining collections | ||
args = {"ortabf": self._street} | ||
r = requests.post( | ||
"https://was-wolfsburg.de/subabfuhrtermine/ics_abfuhrtermine3.php", | ||
data=args, | ||
) | ||
dates = self._ics.convert(r.text) | ||
for d in dates: | ||
entries.append(Collection(d[0], d[1])) | ||
|
||
return entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Wolfsburger Abfallwirtschaft und Straßenreinigung | ||
|
||
Support for schedules provided by [WAS-Wolfsburg.de](https://was-wolfsburg.de). | ||
|
||
Please note that WAS Wolfsburg provides 2 different schedules: One for "Restabfall - Bioabfall - Altpapier" and one for "Gelber Sack". This source fetches both schedules and merges it into one. | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: was_wolfsburg_de | ||
args: | ||
city: CITY | ||
street: STREET | ||
``` | ||
### Configuration Variables | ||
**city**<br> | ||
*(string) (required)* | ||
**street**<br> | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: was_wolfsburg_de | ||
args: | ||
city: Barnstorf | ||
street: Bahnhofspassage | ||
``` | ||
## How to get the source arguments | ||
| Argument | Description | | ||
| ----------- | ----------- | | ||
| city | Full district name as shown in the `Gelber Sack` web page. | | ||
| street | Full street name as shown in the `Restabfall/Bioabfall/Altpapier` web page. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters