Add ProductInformation() class and examples/products.py
This allows the user to re-generate (update) the price list in products.json using ProdWS API, which is a separate API provided by DPAG to obtain the product catalogue including pricing information.
This commit is contained in:
parent
114b6c036b
commit
896ac2abc0
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
from inema import ProductInformation
|
||||||
|
import json
|
||||||
|
|
||||||
|
# you have to fill the below with your login details for the ProdWS Service
|
||||||
|
USER = "xxx"
|
||||||
|
PASS = "yyyyyy"
|
||||||
|
MANDANTID = "zzzzz"
|
||||||
|
|
||||||
|
#logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
im = ProductInformation(USER, PASS, MANDANTID)
|
||||||
|
data = im.getProductList()
|
||||||
|
# print data
|
||||||
|
|
||||||
|
if data['success']:
|
||||||
|
products = {}
|
||||||
|
|
||||||
|
for ele in data['Response']['salesProductList']['SalesProduct']:
|
||||||
|
international = True if ele['extendedIdentifier']['destination'] == 'international' else False
|
||||||
|
id = ele['extendedIdentifier']['externIdentifier'][0]['id']
|
||||||
|
name = ele['extendedIdentifier']['externIdentifier'][0]['name']
|
||||||
|
cost_price = ele['priceDefinition']['price']['commercialGrossPrice']['value']
|
||||||
|
weight = ele['weight']
|
||||||
|
if weight:
|
||||||
|
products[id] = {
|
||||||
|
'international': international,
|
||||||
|
'cost_price': unicode(cost_price),
|
||||||
|
'name': name,
|
||||||
|
'max_weight': unicode(weight['maxValue'])
|
||||||
|
}
|
||||||
|
|
||||||
|
print json.dumps(products)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print 'ERROR: %s' % data['Exception']
|
|
@ -1,3 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from .inema import Internetmarke
|
from .inema import Internetmarke
|
||||||
|
from .inema import ProductInformation
|
||||||
from .inema import __version__
|
from .inema import __version__
|
||||||
|
|
|
@ -7,7 +7,8 @@ import hashlib
|
||||||
import json
|
import json
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from zeep import Client
|
from zeep import Client
|
||||||
from pkg_resources import resource_stream, Requirement
|
from zeep.wsse.username import UsernameToken
|
||||||
|
from pkg_resources import resource_stream
|
||||||
import requests, zipfile
|
import requests, zipfile
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
|
@ -22,6 +23,23 @@ marke_products = json.loads(products_json)
|
||||||
formats_json = resource_stream(__name__, "data/formats.json").read().decode("utf-8")
|
formats_json = resource_stream(__name__, "data/formats.json").read().decode("utf-8")
|
||||||
formats = json.loads(formats_json)
|
formats = json.loads(formats_json)
|
||||||
|
|
||||||
|
class ProductInformation(object):
|
||||||
|
wsdl_url = 'https://prodws.deutschepost.de:8443/ProdWSProvider_1_1/prodws?wsdl'
|
||||||
|
|
||||||
|
def __init__(self, username, password, mandantid):
|
||||||
|
self.client = Client(self.wsdl_url, wsse=UsernameToken(username, password))
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
|
self.mandantid = mandantid
|
||||||
|
|
||||||
|
def getProductList(self):
|
||||||
|
s = self.client.service
|
||||||
|
r = s.getProductList(mandantID=self.mandantid, dedicatedProducts=True, responseMode=0)
|
||||||
|
_logger.info("getProductList result: %s", r)
|
||||||
|
|
||||||
|
return r
|
||||||
|
|
||||||
|
|
||||||
class Internetmarke(object):
|
class Internetmarke(object):
|
||||||
wsdl_url = 'https://internetmarke.deutschepost.de/OneClickForAppV3/OneClickForAppServiceV3?wsdl'
|
wsdl_url = 'https://internetmarke.deutschepost.de/OneClickForAppV3/OneClickForAppServiceV3?wsdl'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue