Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blisko source #3011

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ If your service provider is not listed, feel free to open a [source request issu
<summary>Poland</summary>

- [App Moje Odpady](/doc/source/moje_odpady_pl.md) / moje-odpady.pl
- [Blisko](/doc/source/blisko.md) / gateway.sisms.pl
- [Bydgoszcz Pronatura](/doc/source/pronatura_bydgoszcz_pl.md) / pronatura.bydgoszcz.pl
- [Czerwonak, Murowana Goślina, Oborniki](/doc/source/eko_tom_pl.md) / eko-tom.pl
- [Ecoharmonogram](/doc/source/ecoharmonogram_pl.md) / ecoharmonogram.pl
Expand Down
6 changes: 6 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -11574,6 +11574,12 @@
"default_params": {},
"id": "moje_odpady_pl"
},
{
"title": "Blisko",
"module": "blisko",
"default_params": {},
"id": "blisko"
},
{
"title": "Bydgoszcz Pronatura",
"module": "pronatura_bydgoszcz_pl",
Expand Down
22 changes: 22 additions & 0 deletions custom_components/waste_collection_schedule/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -10097,6 +10097,28 @@
},
"data_description": {}
},
"args_blisko": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nSee blisko.md for help\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md",
"data": {
"calendar_title": "Kalender Titel",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {
"calendar_title": "Ein lesbarerer oder benutzerfreundlicherer Name für den Müllkalender. Wenn nichts angegeben wird, wird der Name der Quelle verwendet."
}
},
"reconfigure_blisko": {
"title": "Quelle Neu Konfigurieren",
"description": "Konfiguriere deinen Service Provider. \n\nSee blisko.md for help\n\nMehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md",
"data": {
"calendar_title": "Kalender Titel",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {}
},
"args_pronatura_bydgoszcz_pl": {
"title": "Quelle konfigurieren",
"description": "Konfiguriere deinen Service Provider. Mehr details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pronatura_bydgoszcz_pl.md",
Expand Down
27 changes: 27 additions & 0 deletions custom_components/waste_collection_schedule/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10103,6 +10103,33 @@
},
"data_description": {}
},
"args_blisko": {
"title": "Configure Source",
"description": "Configure your service provider. \n\nSee blisko.md for help\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md.",
"data": {
"calendar_title": "Calendar Title",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {
"calendar_title": "A more readable, or user-friendly, name for the waste calendar. If nothing is provided, the name returned by the source will be used.",
"formattedId": "Formatted ID of city/street and houseId",
"regionId": "ID of instance owner"
}
},
"reconfigure_blisko": {
"title": "Reconfigure Source",
"description": "Configure your service provider. \n\nSee blisko.md for help\n\nMore details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md.",
"data": {
"calendar_title": "Calendar Title",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {
"formattedId": "Formatted ID of city/street and houseId",
"regionId": "ID of instance owner"
}
},
"args_pronatura_bydgoszcz_pl": {
"title": "Configure Source",
"description": "Configure your service provider. More details: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pronatura_bydgoszcz_pl.md.",
Expand Down
22 changes: 22 additions & 0 deletions custom_components/waste_collection_schedule/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -10086,6 +10086,28 @@
},
"data_description": {}
},
"args_blisko": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nSee blisko.md for help\n\nMaggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md.",
"data": {
"calendar_title": "Nome Calendario",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {
"calendar_title": "Puoi cambiare il nome del calendario della raccolta dei rifiuti, altrimenti di default verra' utilizzato il nome del tuo fornitore di servizi."
}
},
"reconfigure_blisko": {
"title": "Riconfigurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. \n\nSee blisko.md for help\n\nPer maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/blisko.md.",
"data": {
"calendar_title": "Nome Calendario",
"formattedId": "Formatted Id",
"regionId": "Region Id"
},
"data_description": {}
},
"args_pronatura_bydgoszcz_pl": {
"title": "Configurazione Sorgente",
"description": "Compila i campi per ottenere le informazioni sul tuo servizio di raccolta. Maggiori informazioni: https://github.com/mampfes/hacs_waste_collection_schedule/blob/master/doc/source/pronatura_bydgoszcz_pl.md.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import requests
import json
from argparse import ArgumentParser


def all_houses_per_street(regionId: int, streetId: str):
url = "https://gateway.sisms.pl/akun/api/owners/{region}/streetAddresses/list?streetId={formattedSTREET_ID}"
r = requests.get(url.format(
region=regionId, formattedSTREET_ID=streetId))

if r.status_code != 200:
return
return r.json()['data']


def all_houses_per_city_no_streets(regionId: int, townId: str):
url = "https://gateway.sisms.pl/akun/api/owners/{region}/townAddresses/list?townId={formattedTOWN_ID}"
r = requests.get(url.format(region=regionId, formattedTOWN_ID=townId))

if r.status_code != 200:
return

data = r.json()['data']
return data


def all_street_per_city(regionId: int, cityId: str):
url = "https://gateway.sisms.pl/akun/api/owners/{region}/streets/list?townId={formattedTOWN_ID}"
r = requests.get(url.format(region=regionId, formattedTOWN_ID=cityId))

if r.status_code != 200:
return

data = r.json()['data']
return data


def dump_regions(region: int):
url = "https://gateway.sisms.pl/akun/api/owners/{id}/info"
r = requests.get(url.format(id=region))
if r.status_code != 200:
return

region_name = r.json()["name"]

url = "https://gateway.sisms.pl/akun/api/owners/{id}/towns/list"
r = requests.get(url.format(id=region))
if r.status_code != 200:
return
data = r.json()["data"]

return {'region_name': region_name, 'cities': data}


def fetch_one_city(id: int):
url = "https://gateway.sisms.pl/akun/api/owners/{id}/info"
r = requests.get(url.format(id=id))
if r.status_code != 200:
return

data = r.json()
if "TIMETABLE" not in data["tabs"]:
return

return {'id': id, 'region_name': data['name']}


def main():
parser = ArgumentParser()
parser.add_argument('--regionmax', type=int, default=300)
parser.add_argument('--street', type=str, help='formattedId')
parser.add_argument('--city', type=str, help='formattedId')
parser.add_argument('--region', type=int)
parser.add_argument('--dumpregions', action='store_true')
args = parser.parse_args()

if args.region and args.street:
streets_json = all_houses_per_street(
args.region, args.street)
if streets_json:
print(json.dumps(streets_json, indent=2))
else:
print("No houeses for region {} and city {}".format(
args.region, args.city))
return

if args.region and args.city:
streets_json = all_street_per_city(args.region, args.city)
if streets_json:
print(json.dumps(streets_json, indent=2))
else:
print("No streets for region {} and cityId {}. Dumping house addresses".format(
args.region, args.city))
print(json.dumps(all_houses_per_city_no_streets(
args.region, args.city), indent=2))

return

if args.region:
region_json = (dump_regions(args.region))
if not region_json:
print("Region {region} does not exists".format(
region=args.region))
else:
print(json.dumps(region_json, indent=2))
return

if args.dumpregions:
for i in range(args.regionmax):
data = fetch_one_city(i)
if data:
print(json.dumps(data, indent=2))


if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from waste_collection_schedule import Collection

from string import Template
import urllib.request
import datetime
import json
import logging

TITLE = "Blisko"
DESCRIPTION = "Source script for Blisko APP"
URL = "https://gateway.sisms.pl"
COUNTRY = "pl"
TEST_CASES = {
"Gmina Dobra/Grzepnica/Rezydencka": {"regionId": "112",
"formattedId": "32:11:01:2:0774204:42719:32"},
"Gmina Topólka/Bielki": {"regionId": "40",
"formattedId": "02:17:04:3:0880283:00157:1"},
"Gmina Topólka/Bielki": {"regionId": "40",
"formattedId": "04:11:07:2:0870362::1"}
}

API_URL = "https://abc.com/search/"

ICON_MAP = {
"Zmieszane odpady komunalne": "mdi:trash-can",
"Papier i tektura": "mdi:recycle",
"Odpady biodegradowalne": "mdi:leaf",
}

# Arguments affecting the configuration GUI #


HOW_TO_GET_ARGUMENTS_DESCRIPTION = {
"en": "See blisko.md for help",
"pl": "Zobacz w blisko.md"
}

PARAM_DESCRIPTIONS = {
"en": {
"regionId": "ID of instance owner",
"formattedId": "Formatted ID of city/street and houseId"
}
}


def find_bin_name(binId, json):
for entry in json:
if entry['id'] == binId:
return entry['name']
raise Exception


schedule_url_template = Template(
"https://gateway.sisms.pl/akun/api/owners/${regionId}/timetable/get?\
unitId=${formattedId}")


bins_url_template = Template(
"https://gateway.sisms.pl/akun/api/owners/${regionId}/bins/list?\
unitId=${formattedId}")

_LOGGER = logging.getLogger(__name__)


class Source:
# argX correspond to the args dict in the source configuration
def __init__(self, regionId: str, formattedId: str):
self._schedule_url = schedule_url_template.safe_substitute(
regionId=regionId, formattedId=formattedId)
self._bins_url = bins_url_template.safe_substitute(
regionId=regionId, formattedId=formattedId)

def fetch(self):

entries = [] # List that holds collection schedule

bins_data = urllib.request.urlopen(self._bins_url)
bins = json.load(bins_data)['data']
_LOGGER.warn(bins)
timetable_data = urllib.request.urlopen(self._schedule_url)
timetable_json = json.load(timetable_data)["data"]

for month_data in timetable_json:
for reception in month_data['receptions']:
bin_name = find_bin_name(binId=reception['binId'], json=bins)
entries.append(
Collection(
date=datetime.datetime.strptime(
reception['date'], '%Y-%m-%d').date(),
t=bin_name,
icon=ICON_MAP.get(bin_name),
)
)

return entries
Loading