-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathntp.py
47 lines (31 loc) · 827 Bytes
/
ntp.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
import requests
import json
import time
TAG = "NTP"
NTP_URL = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'
def DEBUG(str):
if False:
print(str)
def get_time():
response = requests.get(NTP_URL)
data_json = json.loads(response.text)
api = data_json['api']
ret = data_json['ret']
data = data_json['data']
DEBUG(data_json)
DEBUG(api)
DEBUG(ret)
DEBUG(data)
time_stamp = int(data['t'][0:10])
DEBUG(time_stamp)
time_struct = time.localtime(time_stamp)
DEBUG(time_struct)
time_format = time.strftime('%Y-%m-%d %H:%M:%S', time_struct)
DEBUG(time_format)
data['code'] = 200
data['time_format'] = time_format
data = json.dumps(data)
return data
if __name__ == '__main__':
time = get_time()
print(time)