fixed regex
This commit is contained in:
parent
564a2c61df
commit
4bbafbccf8
@ -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.
|
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\\\"')
|
choice_regex = re.compile(r'businessModel\\\":\\\"CHOICE\\\"')
|
||||||
magnifier_image_regex = re.compile(r'<meta property=\"og:image\" content=\"(https:[0-9a-zA-Z\/\-\_.]*)\"\/>')
|
magnifier_image_regex = re.compile(r'<meta property=\"og:image\" content=\"(https:[0-9a-zA-Z\/\-\_.]*)\"\/>')
|
||||||
|
|
||||||
@ -49,8 +49,8 @@ def check_items(settings_items):
|
|||||||
for elem in content:
|
for elem in content:
|
||||||
if set(get_attributes(elem[0])) == set(filter_attributes):
|
if set(get_attributes(elem[0])) == set(filter_attributes):
|
||||||
key = (item,tuple(filter_attributes))
|
key = (item,tuple(filter_attributes))
|
||||||
discount = 0 if len(elem[5]) == 0 else int(elem[5])
|
discount = 0 if len(elem[7]) == 0 else int(elem[7])
|
||||||
price = float(elem[13]) if len(elem[11]) == 0 else float(elem[11])
|
price = float(elem[15]) if len(elem[13]) == 0 else float(elem[13])
|
||||||
|
|
||||||
# get item image
|
# get item image
|
||||||
image_link = re.findall(magnifier_image_regex, target_page_response.text)[0]
|
image_link = re.findall(magnifier_image_regex, target_page_response.text)[0]
|
||||||
|
@ -34,6 +34,15 @@ def update_hist():
|
|||||||
fill_db(settings["db"], check_items(settings["item"]))
|
fill_db(settings["db"], check_items(settings["item"]))
|
||||||
return 'Hello, World!'
|
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'])
|
@app.route('/datahistory',methods = ['POST', 'GET'])
|
||||||
def data_history_request():
|
def data_history_request():
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -15,7 +15,7 @@ if __name__ == '__main__':
|
|||||||
settings = get_conf()
|
settings = get_conf()
|
||||||
|
|
||||||
# initialize(settings["db"])
|
# initialize(settings["db"])
|
||||||
fill_db(settings["db"], check_items(settings["item"]))
|
# fill_db(settings["db"], check_items(settings["item"]))
|
||||||
|
|
||||||
# export_csv(settings["db"])
|
# export_csv(settings["db"])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user