add source tkeliai_lt (#1897)

* add source tkeliai_lt

* reformatting

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Elijus Gustys
2024-03-17 18:12:50 +02:00
committed by GitHub
parent 8a25d9bdd1
commit 204aceb185
4 changed files with 90 additions and 1 deletions

View File

@@ -1005,6 +1005,7 @@ Waste collection schedules in the following formats and countries are supported.
<summary>Lithuania</summary>
- [Kauno švara](/doc/source/grafikai_svara_lt.md) / grafikai.svara.lt
- [Telšių keliai](/doc/source/tkeliai_lt.md) / tkeliai.lt
</details>
<details>

View File

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

32
doc/source/tkeliai_lt.md Normal file
View File

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

File diff suppressed because one or more lines are too long