Скачать
Код
import sys
import json
import urllib.request
import urllib.parse
import http.client
headers = {"Content-Type":"application/json",
"Api-Key":"YOUR API KEY",
'X-Requested-With':'XMLHttpRequest'
}
class track:
def trackru(requestData, urlStr, method):
if method == "get":
url = 'http://api.trackru.ru/v1/trackings/get'
RelUrl = url + urlStr
req = urllib.request.Request(RelUrl, headers=headers)
result = urllib.request.urlopen(req).read()
elif method == "post":
url = 'http://api.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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.trackru.ru/v1/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