diff --git a/inema/inema.py b/inema/inema.py index 4b96725..8eb332e 100644 --- a/inema/inema.py +++ b/inema/inema.py @@ -25,16 +25,16 @@ _logger = logging.getLogger(__name__) # This allows to ship multiple products.json files for announced future price/product # changes. def load_products(): - global marke_products ps = [ e for e in resource_listdir(__name__, 'data') if e.startswith('products-') and e.endswith('.json') and e <= 'products-{}.json'.format(date.today().isoformat()) ] ps.sort() ps.insert(0, 'products.json') products_json = resource_stream(__name__, 'data/' + ps[-1]).read().decode("utf-8") - marke_products = json.loads(products_json) + products = json.loads(products_json) + return products -load_products() +default_products = load_products() formats_json = resource_stream(__name__, "data/formats.json").read().decode("utf-8") formats = json.loads(formats_json) @@ -94,16 +94,21 @@ class Internetmarke(object): return [p, t, k, s] def get_product_price_by_id(self, ext_prod_id): - price_str = marke_products[str(ext_prod_id)]['cost_price'] + price_str = self.products[str(ext_prod_id)]['cost_price'] return int(decimal.Decimal(price_str) * 100) - def __init__(self, partner_id, key, key_phase="1"): + def __init__(self, partner_id, key, key_phase="1", products=None): self.client = Client(self.wsdl_url) self.partner_id = partner_id self.key_phase = key_phase self.key = key self.soapheader = self.gen_1c4a_hdr(self.partner_id, self.key_phase, self.key) self.positions = [] + if products is None: + self.products = default_products + else: + self.products = products + def authenticate(self, username, password): s = self.client.service