You've already forked Irene-Voice-Assistant
mirror of
https://github.com/janvarev/Irene-Voice-Assistant.git
synced 2025-11-26 22:50:58 +02:00
Initial commit
This commit is contained in:
92
plugins/plugin_yandex_rasp.py
Normal file
92
plugins/plugin_yandex_rasp.py
Normal file
@@ -0,0 +1,92 @@
|
||||
# Яндекс.Расписания - работает точно для электричек
|
||||
# author: Vladislav Janvarev
|
||||
|
||||
import os
|
||||
|
||||
from voiceasscore import VoiceAssCore
|
||||
|
||||
modname = os.path.basename(__file__)[:-3] # calculating modname
|
||||
|
||||
# функция на старте
|
||||
def start(core:VoiceAssCore):
|
||||
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
|
||||
|
||||
def start_with_options(core:VoiceAssCore,manifest:dict):
|
||||
pass
|
||||
|
||||
def run_poezd(core:VoiceAssCore,phrase:str):
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user