Last active
August 10, 2016 07:35
-
-
Save reflechant/6f03df4fac7faf155285853c76f61969 to your computer and use it in GitHub Desktop.
Консольный клиент для сервиса Яндекс.Расписания
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
#!/usr/bin/env python3 | |
import requests | |
import sys | |
import datetime as dt | |
SECRET_KEY = """ Ключ можно получить здесь: https://tech.yandex.ru/rasp/raspapi/ """ | |
p = {"Белорусский вокзал": "s2000006", | |
"Шереметьево": "s9600213" | |
} // к сожалению, получить код станции по API невозможно | |
def convert_time(rasp_datetime): | |
x = rasp_datetime.split()[1] # cut date | |
l = x.split(":") | |
return l[0] + ":" + l[1] # return without seconds | |
def find(src, dest, date): | |
r = requests.get("https://api.rasp.yandex.net/v1.0/search/?" + | |
"apikey=" + SECRET_KEY + | |
"&format=json" + | |
"&from=" + p[src] + | |
"&to=" + p[dest] + | |
"&lang=ru" + | |
"&transport_types=suburban" + | |
"&date=" + date + | |
"&system=yandex") | |
routes = r.json()["threads"] | |
print(src + " - " + dest) | |
for r in routes: | |
dep_time = convert_time(r["departure"]) | |
arr_time = convert_time(r["arrival"]) | |
#print("{} - {}\t{}\t{}\t{}\t{}".format( r["departure"], r["arrival"], r["thread"]["title"], r["stops"], "кроме " + r["except_days"], r["days"] ) ) | |
print("{} - {}\t{}".format(dep_time, arr_time, r["thread"]["title"])) | |
print() | |
if __name__ == "__main__": | |
today = dt.date.today() | |
year, month, day = today.year, today.month, today.day | |
date = str(year) + "-" + str(month) + "-" + str(day) | |
find("Белорусский вокзал", "Шереметьево", date) | |
find("Шереметьево", "Белорусский вокзал", date) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment