2021-12-14 12:51:47 +03:00
|
|
|
# Яндекс.Расписания - работает точно для электричек
|
|
|
|
|
# author: Vladislav Janvarev
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
2021-12-15 12:53:52 +03:00
|
|
|
from vacore import VACore
|
2021-12-14 12:51:47 +03:00
|
|
|
|
|
|
|
|
modname = os.path.basename(__file__)[:-3] # calculating modname
|
|
|
|
|
|
|
|
|
|
# функция на старте
|
2021-12-15 12:53:52 +03:00
|
|
|
def start(core:VACore):
|
2021-12-14 12:51:47 +03:00
|
|
|
manifest = {
|
|
|
|
|
"name": "Яндекс Расписания",
|
|
|
|
|
"version": "1.0",
|
|
|
|
|
"require_online": True,
|
|
|
|
|
|
|
|
|
|
"default_options": {
|
|
|
|
|
"apiKey": "", # get at https://yandex.ru/dev/rasp/raspapi/
|
|
|
|
|
|
|
|
|
|
"from": "s9600681",
|
|
|
|
|
"to1": "s2000002",
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"commands": {
|
|
|
|
|
"ближайший поезд|электричка|электрички": run_poezd,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return manifest
|
|
|
|
|
|
2021-12-15 12:53:52 +03:00
|
|
|
def start_with_options(core:VACore, manifest:dict):
|
2021-12-14 12:51:47 +03:00
|
|
|
pass
|
|
|
|
|
|
2021-12-15 12:53:52 +03:00
|
|
|
def run_poezd(core:VACore, phrase:str):
|
2021-12-14 12:51:47 +03:00
|
|
|
|
|
|
|
|
options = core.plugin_options(modname)
|
|
|
|
|
|
|
|
|
|
if options["apiKey"] == "":
|
|
|
|
|
core.play_voice_assistant_speech("Нужен ключ апи для получения расписания")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
# datetime
|
|
|
|
|
import datetime
|
|
|
|
|
now = datetime.datetime.now().__str__()
|
|
|
|
|
print(now)
|
|
|
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
|
current_date = date.today().__str__()
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
res = requests.get("https://api.rasp.yandex.net/v3.0/search/",
|
|
|
|
|
params={'from': options["from"], 'to': options["to1"], 'format':'json',
|
|
|
|
|
'date': current_date,
|
|
|
|
|
'apikey': options["apiKey"]})
|
|
|
|
|
data = res.json()
|
|
|
|
|
print(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cnt = 1
|
|
|
|
|
txt = ""
|
|
|
|
|
for segment in data["segments"]:
|
|
|
|
|
dep = str(segment["departure"]).replace("T"," ")
|
|
|
|
|
if dep > now:
|
|
|
|
|
hours = dep[11:13]
|
|
|
|
|
min = dep[14:16]
|
|
|
|
|
if cnt == 1:
|
|
|
|
|
txt += "Ближайшая электричка в {0} {1}. ".format(hours,min)
|
|
|
|
|
#print(txt)
|
|
|
|
|
cnt += 1
|
|
|
|
|
elif cnt == 2:
|
|
|
|
|
txt += "Следующая в {0} {1}. ".format(hours,min)
|
|
|
|
|
#print(txt)
|
|
|
|
|
cnt += 1
|
|
|
|
|
|
|
|
|
|
elif cnt == 3:
|
|
|
|
|
txt += "Дальше в {0} {1}. ".format(hours,min)
|
|
|
|
|
#print(txt)
|
|
|
|
|
cnt += 1
|
|
|
|
|
break
|
|
|
|
|
#print(dep)
|
|
|
|
|
print(txt)
|
|
|
|
|
core.play_voice_assistant_speech(txt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
import traceback
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
core.play_voice_assistant_speech("Проблемы с расписанием. Посмотрите логи")
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|