-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpressCollection.py
More file actions
41 lines (33 loc) · 1.08 KB
/
Copy pathExpressCollection.py
File metadata and controls
41 lines (33 loc) · 1.08 KB
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
"""
解析数据
"""
import requests
from prettytable import PrettyTable
class ExpressCollection:
header = '时间 地点和跟踪进度'.split()
express_data = None
def __init__(self, express_url):
self.express_url = express_url
self.handleData(self.getJson())
def getJson(self):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36'
}
response = requests.get(self.express_url, headers=headers)
return response.json()
def property(self):
for express in self.express_data:
data = []
data.append(express['time'])
data.append(express['context'])
yield data
def handleData(self, json):
if not int(json['status']) == 200:
print(json['message'])
pass
self.express_data = json['data']
pt = PrettyTable()
pt._set_field_names(self.header)
for data in self.property():
pt.add_row(data)
print(pt)