Skip to content

Instantly share code, notes, and snippets.

@reflechant
Last active September 9, 2019 15:11
Show Gist options
  • Save reflechant/2bb59e60028b276b2594 to your computer and use it in GitHub Desktop.
Save reflechant/2bb59e60028b276b2594 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
import sys
import datetime as dt
SECRET_KEY = "get it yourself @ yandex"
p = { "Одинцово" : "s9600721",
"Голицыно": "s9602265",
"Савёловский вокзал" : "s2000009",
"Савёловская" : "s9601382" }
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