From 4bbafbccf8907bd280b0a23f913232e32a8c11ff Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Mon, 29 Jan 2024 00:42:20 +0100 Subject: [PATCH] fixed regex --- src/aliexpress.py | 6 +++--- src/app.py | 9 +++++++++ src/main.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/aliexpress.py b/src/aliexpress.py index 646bf52..ab332bf 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]*:[0-9]*#[a-zA-Z0-9 ]*;?)*)\\\",\\\"skuId\\\":([0-9]*),\\\"skuIdStr\\\":\\\"[0-9]*\\\",\\\"skuPropIds\\\":\\\"[0-9,]*\\\",\\\"skuVal\\\":{\\\"availQuantity\\\":([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'') @@ -49,8 +49,8 @@ def check_items(settings_items): for elem in content: if set(get_attributes(elem[0])) == set(filter_attributes): key = (item,tuple(filter_attributes)) - discount = 0 if len(elem[5]) == 0 else int(elem[5]) - price = float(elem[13]) if len(elem[11]) == 0 else float(elem[11]) + discount = 0 if len(elem[7]) == 0 else int(elem[7]) + price = float(elem[15]) if len(elem[13]) == 0 else float(elem[13]) # get item image image_link = re.findall(magnifier_image_regex, target_page_response.text)[0] diff --git a/src/app.py b/src/app.py index 9ab539c..475fdff 100644 --- a/src/app.py +++ b/src/app.py @@ -34,6 +34,15 @@ def update_hist(): fill_db(settings["db"], check_items(settings["item"])) return 'Hello, World!' +@app.route('/add',methods = ['POST']) +def add_item(): + print("adding item") + itemid = request.form['itemid'] + attributes = request.form['attributes'].split(',') + new_item = [(itemid, attributes)] + extr = check_items(new_item) + return str(extr['skuid']) + @app.route('/datahistory',methods = ['POST', 'GET']) def data_history_request(): if request.method == 'GET': diff --git a/src/main.py b/src/main.py index f41c9b8..77dc717 100644 --- a/src/main.py +++ b/src/main.py @@ -15,7 +15,7 @@ if __name__ == '__main__': settings = get_conf() # initialize(settings["db"]) - fill_db(settings["db"], check_items(settings["item"])) + # fill_db(settings["db"], check_items(settings["item"])) # export_csv(settings["db"])