Last active
April 29, 2018 03:01
-
-
Save BlaayLock/89253daf502cc8b2b60dc991e4f283b3 to your computer and use it in GitHub Desktop.
DPD Tracking API python scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! python2 | |
# //coding: utf-8 | |
''' | |
29 april 2018 http://ws.dpd.ru:80/services/tracing?wsdl | |
Проверка и нормализация адреса с помощью SoapUI, подробно https://otpravka.pochta.ru/specification#/usecases-soapui-clean_address | |
Скачайте и установите SoapUI | |
1 шаг: Скачайте и установите SoapUI | |
-1. Перейдите по ссылке SoapUI. | |
-2. Скачайте "SoapUI OpenSource" бесплатную версию. | |
-3. Установите SoapUI. | |
2 шаг: Запустите SoapUI и создайте REST проект | |
После запуска: | |
-1. Создайте "REST" проект | |
-2. Укажите ссылку "http://ws.dpd.ru:80/services/tracing?wsdl" на API Онлайн-сервиса «Отправка». | |
-3. Нажмите на кнопку "OK" | |
''' | |
import xmltodict, json | |
import requests | |
xml = (''' | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://dpd.ru/ws/tracing/2011-11-18"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<ns:getStatesByDPDOrder> | |
<!--Optional:--> | |
<request> | |
<auth> | |
<clientNumber>1131000999</clientNumber> | |
<clientKey>4E8999726B106BAD7B03C59998A25B3A0BB8999C</clientKey> | |
</auth> | |
<dpdOrderNr>RU009920999</dpdOrderNr> | |
<!--Optional:--> | |
</request> | |
</ns:getStatesByDPDOrder> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
''') | |
target_url = "http://ws.dpd.ru:80/services/tracing" | |
headers={'Content-type': 'text/xml'} | |
response = requests.post(target_url, data=xml, headers=headers) | |
response_obj = xmltodict.parse(response.text) | |
obj=response_obj['S:Envelope']['S:Body']['ns2:getStatesByDPDOrderResponse']['return'] | |
docId=obj['docId'] | |
resultComplete=obj['resultComplete'] | |
for it in obj['states']: | |
print it['transitionTime'] | |
print it['newState'] | |
print it['terminalCity'].encode('UTF-8') | |
print '----------------------' | |
try: | |
consignee=it['consignee'] | |
except: | |
consignee='' | |
print docId,resultComplete,consignee | |
''' | |
http://order.dpd.ru/#/order-info/ | |
Для отслеживания необходимо использовать методы интеграции : | |
getStatesByClient, getStatesByClientOrder, getStatesByClientParcel, getStatesByDPDOrder, getEvents. | |
http://ws.dpd.ru:80/services/tracing - 70.000 запросов в сутки. | |
Методы: confirm, getStatesByClient, getStatesByClientOrder, getStatesByClientParcel, getStatesByDPDOrder | |
http://ws.dpd.ru:80/services/tracing1-1 - 50.000 запросов в сутки. | |
Методы: getStatesByClientOrder, getStatesByClientParcel, getStatesByDPDOrder | |
Доступные методы: | |
tracing?wsdl – confirm, getStatesByClient, getStatesByClientOrder, getStatesByClientParcel, getStatesByDPDOrder. | |
tracing1-1?wsdl – getStatesByClientOrder, getStatesByClientParcel, getStatesByDPDOrder | |
event-tracking - confirm, getEvents | |
''' | |
import xmltodict, json | |
import requests | |
xml = (''' | |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://dpd.ru/ws/calculator/2012-03-20"> | |
<soapenv:Header/> | |
<soapenv:Body> | |
<ns:getServiceCost2> | |
<!--Optional:--> | |
<request> | |
<auth> | |
<clientNumber>1131000999</clientNumber> | |
<clientKey>4E8999726B106BAD7B03C59998A25B3A0BB8999C</clientKey> | |
</auth> | |
<pickup> | |
<cityId>49694102</cityId> | |
</pickup> | |
<delivery> | |
<cityId>49265227</cityId> | |
</delivery> | |
<selfPickup>true</selfPickup> | |
<selfDelivery>false</selfDelivery> | |
<weight>0.5</weight> | |
<serviceCode>PCL</serviceCode> | |
</request> | |
</ns:getServiceCost2> | |
</soapenv:Body> | |
</soapenv:Envelope> | |
''') | |
target_url = "http://wstest.dpd.ru:80/services/calculator2" | |
headers={'Content-type': 'text/xml'} | |
response = requests.post(target_url, data=xml, headers=headers) | |
response_obj = xmltodict.parse(response.text) | |
obj=response_obj['S:Envelope']['S:Body']['ns2:getServiceCost2Response']['return'] | |
cost=obj['cost'] | |
days=obj['days'] | |
print cost, ' ,by day:', days |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment