forked from mampfes/hacs_waste_collection_schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add source tkeliai_lt (mampfes#1897)
* add source tkeliai_lt * reformatting --------- Co-authored-by: 5ila5 <[email protected]>
- Loading branch information
1 parent
8a25d9b
commit 204aceb
Showing
4 changed files
with
90 additions
and
1 deletion.
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
56 changes: 56 additions & 0 deletions
56
custom_components/waste_collection_schedule/waste_collection_schedule/source/tkeliai_lt.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,56 @@ | ||
import datetime | ||
import json | ||
|
||
import requests | ||
from waste_collection_schedule import Collection # type: ignore[attr-defined] | ||
|
||
TITLE = "Telšių keliai" | ||
DESCRIPTION = "Source script for UAB 'Telšių keliai'" | ||
URL = "https://tkeliai.lt/" | ||
TEST_CASES = { | ||
"TestName1": {"location": "Butkų Juzės(1-31) g."}, | ||
"TestName2": {"location": "Paragai k."}, | ||
"TestName3": {"location": "Žalioji g."}, | ||
} | ||
|
||
API_URL = "https://tkeliai.lt/ajax.php" | ||
ICON_MAP = { | ||
"Mišrios komunalinės atliekos": "mdi:trash-can", | ||
"Kitos pakuočių atliekos": "mdi:recycle", | ||
"Stiklo pakuočių atliekos": "mdi:glass-fragile", | ||
} | ||
|
||
|
||
class Source: | ||
def __init__(self, location): | ||
self.location = location | ||
|
||
def fetch(self): | ||
data = { | ||
"action": "getDataAll", | ||
"module": "Atliekos", | ||
"lang": "lt", | ||
"location": self.location, | ||
} | ||
headers = { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"User-Agent": "", | ||
} | ||
|
||
response = requests.post(API_URL, headers=headers, data=data) | ||
|
||
data = json.loads(response.text) | ||
|
||
entries = [] | ||
|
||
for collection in data["return"]: | ||
for date in collection["dates"].keys(): | ||
entries.append( | ||
Collection( | ||
date=datetime.datetime.strptime(date, "%Y-%m-%d").date(), | ||
t=collection["title"], | ||
icon=ICON_MAP.get(collection["title"]), | ||
) | ||
) | ||
|
||
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,32 @@ | ||
# Telšių keliai | ||
|
||
Support for schedules provided by [Telšių keliai](https://tkeliai.lt). | ||
|
||
## Configuration via configuration.yaml | ||
|
||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: tkeliai_lt | ||
args: | ||
location: LOCATION | ||
``` | ||
### Configuration Variables | ||
**location** | ||
*(string) (required)* | ||
## Example | ||
```yaml | ||
waste_collection_schedule: | ||
sources: | ||
- name: tkeliai_lt | ||
args: | ||
location: Butkų Juzės(1-31) g. | ||
``` | ||
## How to get the source arguments | ||
Visit the [Atliekų išvežimo grafikas](https://tkeliai.lt/kalendorius/) page and search for your address. |
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