Guest User

coolkeg

a guest
Sep 29th, 2015
17
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import hashlib
  2. import logging
  3.  
  4. from suds import WebFault
  5. from suds.client import Client
  6.  
  7. logger = logging.getLogger(__name__)
  8. logging.getLogger('suds.client').setLevel(logging.CRITICAL)
  9. logging.basicConfig(level=logging.DEBUG)
  10.  
  11. login = 'yyy'
  12. password = 'xxx'
  13. api_key = '00000000'
  14.  
  15. class AllegroWebAPI(Client):
  16.     country_code = 1  # Poland
  17.     country_id = 1  # Poland
  18.     endpoint = 'http://webapi.allegro.pl/uploader.php?wsdl'
  19.  
  20.     def __init__(self, api_key, login, password):
  21.         self.api_key = api_key
  22.         self.login = login
  23.         self.enc_passwd = hashlib.sha256(password).digest().encode('base64')
  24.         self.client = Client(self.endpoint)
  25.         self.service = self.client.service
  26.  
  27.         self.result = self.service.doQuerySysStatus(self.country_code, self.country_id, api_key)
  28.         self.version = self.result['ver-key']
  29.  
  30.         self.sign_in()
  31.  
  32.     def sign_in(self):
  33.         """Authenticates using encrypted password."""
  34.         session = self.service.doLoginEnc(self.login, self.enc_passwd, self.country_code, self.api_key, self.version)
  35.         self.session_id = session['session-handle-part']
  36.         self.session = session
  37.  
  38.     def get_offers(self):
  39.         return self.doGetMySellItems(self.session_id)
  40.  
  41.  
  42. client = AllegroWebAPI(api_key, login, password)
  43.  
  44. print(client.get_offers())
RAW Paste Data