-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathul_api.py
65 lines (48 loc) · 1.68 KB
/
ul_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#################################################################
# #
# #
# #
#################################################################
import requests
import json
import datetime
import pytz
from io import BytesIO
import pycurl
import re
def addtwohour(editTime):
timeOb = datetime.datetime.strptime(editTime,'%H:%M')
return '{:%H:%M}'.format(timeOb + datetime.timedelta(hours=2))
def getTravelInfoNowJson(fromStationID, toStationID):
now = datetime.datetime.now(pytz.timezone('Europe/Stockholm'))
date = now.strftime('%Y-%m-%d')
time = now.time().strftime('%H:%M')
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.ul.se/api/v2/journeys/?fromPointId='+str(fromStationID)+'&fromPointType=0&toPointId='+str(toStationID)+'&toPointType=0&dateTime=' + date + 'T' + time + ':00.000Z&directionType=0')
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
body = buffer.getvalue()
obj = json.loads(body.decode('utf-8'))
return obj
def getTravelInfoNowJson(fromStationID, toStationID, date, time):
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.ul.se/api/v2/journeys/?fromPointId='+str(fromStationID)+'&fromPointType=0&toPointId='+str(toStationID)+'&toPointType=0&dateTime=' + date + 'T' + time + ':00.000Z&directionType=0')
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
body = buffer.getvalue()
obj = json.loads(body.decode('utf-8'))
return obj
def searchBusStationJson(name):
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.ul.se/api/v2/stops/?query=' + name)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
body = buffer.getvalue()
obj = json.loads(body.decode('utf-8'))
print(obj)