Skip to content

Instantly share code, notes, and snippets.

@BlaayLock
Last active February 19, 2021 06:13
Show Gist options
  • Save BlaayLock/f70ee8b56bc478a7f11572554b010539 to your computer and use it in GitHub Desktop.
Save BlaayLock/f70ee8b56bc478a7f11572554b010539 to your computer and use it in GitHub Desktop.
API cdek for Python Метод для работы с API транспортной компании СДЭК
#!/usr/bin/python
# -*- coding: UTF-8 -*-
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.1'}
import certifi
import requests
import hashlib,time
import datetime
#~ http://gw.edostavka.ru:11443/info_report.php
#~ http://gw.edostavka.ru:11443/status_report_h.php
#~ http://api.cdek.ru/calculator/calculate_price_by_json.php
now = datetime.datetime.now()
now -= datetime.timedelta(days=10)
date = str(now.strftime("%Y-%m-%dT%H:%M:%S"))
secure=hashlib.md5((date+"&15c5adF6s2fe80e9d42f607844cGhkf1170ee3").encode("utf")).hexdigest()
urlf="http://integration.cdek.ru/status_report_h.php/status_report_h.php?account=70c9b93416f4600000000b097f04&secure="+secure+"&datefirst="+date+"&showhistory=1"
r = requests.get(urlf, stream=True, headers=headers,verify=False)
import xmltodict
import json
data= json.loads(json.dumps(xmltodict.parse(r.text.encode('UTF-8'), process_namespaces=True)))
print(json.dumps(data, indent=4, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment