-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbus_tool.py
123 lines (94 loc) · 3.11 KB
/
bus_tool.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# -*- coding: utf-8 -*-
"""
Created on Mon May 08 22:21:49 2017
@author: James
"""
import requests
import json
URL = "http://ikuass.kuas.edu.tw/"
class ikuasbus:
def __init__(self, date):
url = URL + "Bus/GetTimetable"
payload = {
"apiKey": "87vGou@pHO9nhk2",
"drivedate": date
}
r = requests.post(url, data=payload)
r = r.text
self.url = url
self.data = payload
self.data = json.loads(r)
def get_busid(self, n):
return self.data['data'][n]['busId']
def get_driveTime(self, n):
return self.data['data'][n]['driveTime']
def get_startStation(self, n):
return self.data['data'][n]['startStation']
def get_endStation(self, n):
return self.data['data'][n]['endStation']
def get_specialBus(self, n):
return self.data['data'][n]['specialBus']
def get_specialMsg(self, n):
return self.data['data'][n]['specialMsg']
def get_resCount(self,n):
return self.data['data'][n]['resCount']
def get_limitCount(self,n):
return self.data['data'][n]['limitCount']
def get_resEnable(self, n):
return self.data['data'][n]['resEnable']
def get_resCode(self, n):
return self.data['data'][n]['resCode']
def get_resName(self, n):
return self.data['data'][n]['resName']
def get_datalen(self):
return len(self.data['data'])
def updatabus(self):
r = requests.post(self.url, data=self.data)
r = r.text
self.data = json.loads(r)
class ikuaslogin:
def __init__(self, userId, userPw):
url = URL + 'User/DoLogin'
payload = {
"apiKey": "87vGou@pHO9nhk2",
"userId": userId,
"userPw": userPw,
"userKeep": "0"
}
r = requests.post(url, data=payload)
r = r.text
self.data = json.loads(r)
self.Id = userId
self.Pw = userPw
def get_userKey(self):
return self.data['data']['userKey']
def get_userName(self):
return self.data['data']['userName']
def get_userEmail(self):
return self.data['data']['userEmail']
def get_userMobile(self):
return self.data['data']['userMobile']
class ikuasset:
def __init__(self, userName, userKey):
self.Tf = None
self.Ans = None
self.Name = userName
self.Key = userKey
def busset(self, busid):
url = 'http://ikuass.kuas.edu.tw/Bus/CreateUserReserve'
# API URL 預約校車
payload = {
"apiKey": self.Key,
"userId": self.Name,
"busId": busid
}
r = requests.post(url, data=payload)
r = r.text
data = json.loads(r)
self.Tf = data['success']
self.Ans = data['message']
return data['message']
def get_success(self):
return self.Tf
def get_message(self):
return self.Ans