Beispiel #1
0
def get_product_data(gtin):
    db = ORM()

    product = db.get_cache(gtin)

    if product:
        return product[0]

    prod = product_data(gtin)
    prod = prod.get('products', [])
    if not prod:
        print(f'There is not products with gtin {gtin}')
        return None
    descr = prod[0].get('description')
    first_word_of_descr = descr.split(' ')[0]
    tpnc = prod[0].get('tpnc')

    offset = 0
    glosery = grocery_search(descr, offset)
    product = get_necessary_data_from_grocery_search(glosery, tpnc)

    while not product and offset < 10:
        offset += 1
        glosery = grocery_search(first_word_of_descr, offset)
        product = get_necessary_data_from_grocery_search(glosery, tpnc)

    if product:
        db.add_cache(gtin, **product)

    return product
Beispiel #2
0
def add():
    data = request.get_json()
    gtin = data['gtin']
    quantity = data['quantity']
    shop_id = data['shop_id']
    orm = ORM()
    products = orm.get_cache(gtin)
    orm.add_catalog(gtin, quantity, shop_id)
    return jsonify({'quantity': quantity, 'products': products})
Beispiel #3
0
def barcode_processing():
    data = request.get_json()
    gtin = data['gtin']
    shop_id = data['shop_id']
    product = api.get_product_data(gtin)

    how_much_will_be_waist = ml.predict(product)
    # TODO: Send how_much_will_be_waist to mobile

    orm = ORM()
    products = orm.get_cache(gtin)
    orm.add_catalog(gtin, how_much_will_be_waist, shop_id)
    return jsonify({
        'how_much_will_be_waist': how_much_will_be_waist,
        'products': products
    })