def parseFile(self): print 'Parsing product file...' productsRegular = [] productsPromo = [] # open products file and process items with open(Utils.getConfig()['productFile']) as json_file: json_data = json.load(json_file) for item in json_data: product = {} # not available products are omitted # if item['avail'] == self.PROD_NOT_AVAIL: # continue product['id'] = long(item['id']) product['price'] = float(item['price']) product['category'] = item['cat'] # product['name'] = data['name'].encode('utf-8') product['url'] = item['url'].encode('utf-8') # in case of regular product add it to separate table if item.get('oldPr', None) is None: product['date'] = self.dateTime[:10] productsRegular.append(product) else: product['old_price'] = item['oldPr'] product['discount'] = item['disc'] # product['description'] = data['descr'].encode('utf-8') product['url'] = item['url'].encode('utf-8') productsPromo.append(product) self.updateRegularProducts(productsRegular) self.updatePromoProducts(productsPromo) Utils.renameFile(Utils.getConfig()['productFile'])
def parseFile(self): print "Parsing product file..." productsRegular = [] productsPromo = [] # open products file and process items with open(Utils.getConfig()["productFile"]) as json_file: json_data = json.load(json_file) for item in json_data: product = {} # not available products are omitted # if item['avail'] == self.PROD_NOT_AVAIL: # continue try: product["id"] = long(item["id"]) product["price"] = float(item["price"]) product["category"] = item["cat"] # product['name'] = data['name'].encode('utf-8') product["url"] = item["url"].encode("utf-8") # in case of regular product add it to separate table if item.get("oldPr", None) is None: product["date"] = self.dateTime[:10] productsRegular.append(product) else: product["old_price"] = item["oldPr"] product["discount"] = item["disc"] # product['description'] = data['descr'].encode('utf-8') product["url"] = item["url"].encode("utf-8") productsPromo.append(product) except: pass self.updateRegularProducts(productsRegular) self.updatePromoProducts(productsPromo) Utils.renameFile(Utils.getConfig()["productFile"])
def finish(self): print("Więcej informacji: https://github.com/thof/decapromolist#decapromolist" + self.SPACES, file=self.mdFile) print( "PayPal: [email protected]_ (w razie gdyby ktoś chciał wspomóc projekt)" + self.SPACES, file=self.mdFile, ) self.mdFile.close() Utils.renameFile(Utils.getConfig()["decapromolistFile"]) Utils.saveJsonFile(Utils.getConfig()["decapromolistFile"], self.products)
def saveSubcategories(self, dataCat): Utils.renameFile(Utils.getConfig()["subcatFile"]) Utils.saveJsonFile(Utils.getConfig()["subcatFile"], dataCat)
def __init__(self): self.products = [] Utils.renameFile(Utils.getConfig()["decapromolistMDFile"]) self.mdFile = open(Utils.getConfig()["decapromolistMDFile"], "w") with open(Utils.getConfig()["subcatFile"]) as jsonFile: self.subcatData = json.load(jsonFile)