forked from abdullahafzal/ups-tracking-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackingmoreclass.py
141 lines (99 loc) · 5.49 KB
/
trackingmoreclass.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
import json
import urllib.request
import urllib.parse
import http.client
headers={"Content-Type":"application/json",
"Trackingmore-Api-Key":"YOUR API KEY",
'X-Requested-With':'XMLHttpRequest'
}
class track:
def trackingmore(requestData, urlStr, method):
if method == "get":
url = 'http://api.trackingmore.com/v2/trackings/get'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl, headers=headers)
result = urllib.request.urlopen(req).read()
elif method == "post":
url = 'http://api.trackingmore.com/v2/trackings/post'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "batch":
url = 'http://api.trackingmore.com/v2/trackings/batch'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "codeNumberGet":
url = 'http://api.trackingmore.com/v2/trackings'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="GET")
result = urllib.request.urlopen(req).read()
elif method == "codeNumberPut":
url = 'http://api.trackingmore.com/v2/trackings'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="PUT")
result = urllib.request.urlopen(req).read()
elif method == "codeNumberDelete":
url = 'http://api.trackingmore.com/v2/trackings'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="DELETE")
result = urllib.request.urlopen(req).read()
elif method == "realtime":
url = 'http://api.trackingmore.com/v2/trackings/realtime'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "carriers":
url = 'http://api.trackingmore.com/v2/carriers'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="GET")
result = urllib.request.urlopen(req).read()
elif method == "carriers/detect":
url = 'http://api.trackingmore.com/v2/carriers/detect'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="GET")
result = urllib.request.urlopen(req).read()
elif method == "update":
url = 'http://api.trackingmore.com/v2/trackings/update'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "getuserinfo":
url = 'http://api.trackingmore.com/v2/trackings/getuserinfo'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="GET")
result = urllib.request.urlopen(req).read()
elif method == "getstatusnumber":
url = 'http://api.trackingmore.com/v2/trackings/getstatusnumber'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="GET")
result = urllib.request.urlopen(req).read()
elif method == "notupdate":
url = 'http://api.trackingmore.com/v2/trackings/notupdate'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "remote":
url = 'http://api.trackingmore.com/v2/trackings/remote'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "costtime":
url = 'http://api.trackingmore.com/v2/trackings/costtime'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "delete":
url = 'http://api.trackingmore.com/v2/trackings/delete'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
elif method == "updatemore":
url = 'http://api.trackingmore.com/v2/trackings/updatemore'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl,requestData.encode('utf-8'), headers=headers,method="POST")
result = urllib.request.urlopen(req).read()
return result