From c19fac2dc52977a1e210e746a3147a7e7909821d Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Mon, 29 Jan 2024 00:56:02 +0100 Subject: [PATCH] regex fix, items with no attributes --- src/aliexpress.py | 2 +- src/app.py | 7 +++++-- src/main.py | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/aliexpress.py b/src/aliexpress.py index ab332bf..a06ec12 100644 --- a/src/aliexpress.py +++ b/src/aliexpress.py @@ -29,7 +29,7 @@ def check_items(settings_items): itemid is in aliexpress link to item page. attributes is a list of string. Each string is a choice value (for example which length, or which colour) if multiple items are on the same page, only one by category, order doesn't matter. ''' - item_regex = re.compile(r'skuAttr\\\":\\\"([0-9:;]*#([a-zA-Z0-9 ]*;?)*)\\\",\\\"skuId\\\":([0-9]*),\\\"skuIdStr\\\":\\\"[0-9]*\\\",\\\"skuPropIds\\\":\\\"[0-9,]*\\\",\\\"skuVal\\\":{\\\"availQuantity\\\":([0-9]*),(\\\"(bulkOrder)\\\":[0-9]*,)?(\\\"discount\\\":\\\"([0-9]*)\\\",\\\"discountTips\\\":\\\"-[0-9]*%\\\",)?\\\"hideOriPrice\\\":(false|true),\\\"inventory\\\":([0-9]*),\\\"isActivity\\\":(true|false),\\\"optionalWarrantyPrice\\\":\[\],(\\\"skuActivityAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)},\\\"skuActivityAmountLocal\\\":\\\"[0-9]*,[0-9]*.\|[0-9]*\|[0-9]*\\\",)?\\\"skuAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)}') + item_regex = re.compile(r'skuAttr\\\":\\\"([0-9:;]*#([a-zA-Z0-9 ]*;?)*)?\\\",\\\"skuId\\\":([0-9]*),\\\"skuIdStr\\\":\\\"[0-9]*\\\",\\\"skuPropIds\\\":\\\"[0-9,]*\\\",\\\"skuVal\\\":{\\\"availQuantity\\\":([0-9]*),(\\\"bulkOrder\\\":([0-9]*),)?(\\\"discount\\\":\\\"([0-9]*)\\\",\\\"discountTips\\\":\\\"-[0-9]*%\\\",)?\\\"hideOriPrice\\\":(false|true),\\\"inventory\\\":([0-9]*),\\\"isActivity\\\":(true|false),\\\"optionalWarrantyPrice\\\":\[\],(\\\"skuActivityAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)},\\\"skuActivityAmountLocal\\\":\\\"[0-9]*,[0-9]*.\|[0-9]*\|[0-9]*\\\",)?\\\"skuAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)}') choice_regex = re.compile(r'businessModel\\\":\\\"CHOICE\\\"') magnifier_image_regex = re.compile(r'') diff --git a/src/app.py b/src/app.py index 475fdff..2fa3d73 100644 --- a/src/app.py +++ b/src/app.py @@ -38,10 +38,13 @@ def update_hist(): def add_item(): print("adding item") itemid = request.form['itemid'] - attributes = request.form['attributes'].split(',') + if len(request.form['attributes'])>0: + attributes = request.form['attributes'].split(',') + else: + attributes = [] new_item = [(itemid, attributes)] extr = check_items(new_item) - return str(extr['skuid']) + return str(extr) @app.route('/datahistory',methods = ['POST', 'GET']) def data_history_request(): diff --git a/src/main.py b/src/main.py index 77dc717..998c085 100644 --- a/src/main.py +++ b/src/main.py @@ -14,6 +14,14 @@ if __name__ == '__main__': settings = get_conf() + c_l = [("33058732737",["3 M Probe"])] + print(check_items(c_l)) + c_l = [("1005005769229528", ["2 E27 Clip EU"])] + print(check_items(c_l)) + c_l = [("1005004130931033", [])] + print(check_items(c_l)) + + # initialize(settings["db"]) # fill_db(settings["db"], check_items(settings["item"]))