Ejemplo n.º 1
0
def update_profitable_products(shop_name):
    data = get_data()
    profitable = data[(data["profit"] > 0) & (data["shop_name"] == shop_name)]
    profitable_ean_list = profitable["ean"]

    session = Session()
    query = session.query(ProductAmazon).filter(
        ProductAmazon.ean.in_(profitable_ean_list))
    for cur_product in tqdm(query, total=query.count()):
        update_rating_and_sales_info(cur_product, session)
    session.close()
Ejemplo n.º 2
0
def update_database(shop_name):
    session = Session()

    batch_size = 5
    cur_batch = []
    query = session.query(ProductWholesale).filter_by(shop_name=shop_name)
    for cur_product in tqdm(query, total=query.count()):
        if len(cur_batch) < batch_size:
            cur_batch.append(cur_product)
        else:
            update_products(cur_batch, session)
            cur_batch = [cur_product]
    if len(cur_batch) > 0:
        update_products(cur_batch, session)

    session.close()
Ejemplo n.º 3
0
class SaraswatiScrapyPipeline:
    def __init__(self):
        self.session = Session()

    def process_item(self, item, spider):

        if item.ean == "":
            return item

        old_product = (self.session.query(ProductWholesale).filter_by(
            shop_name=item.shop_name, ean=item.ean).first())

        if old_product is None:
            self.session.add(item)
            self.session.commit()
        elif not old_product == item:
            old_product.update(item)
            self.session.commit()

        return item

    def close_spider(self, spider):
        self.session.close()
Ejemplo n.º 4
0
def update_no_offer_products():
    session = Session()

    sum_offers = (func.sum(ProductAmazon.offers)).label("sum_offers")
    query = (session.query(ProductAmazon.ean, sum_offers).group_by(
        ProductAmazon.ean).having(sum_offers == 0))
    ean_list = [cur_product.ean for cur_product in query]
    query = session.query(ProductAmazon).filter(
        ProductAmazon.ean.in_(ean_list))
    for cur_product in tqdm(query, total=query.count()):
        update_rating_and_sales_info(cur_product, session)

    session.close()
Ejemplo n.º 5
0
def clean_profitable_products():
    df = data_loader.get_data()
    df = df[(df["shop_name"] == shop_name) & (df["profit"] > 0)]
    ean_list = df["ean"]

    session = Session()
    query = session.query(ProductWholesale).filter(
        ProductWholesale.ean.in_(ean_list))
    for cur_product in tqdm(query, total=query.count()):

        def availability_check_request():
            return is_available(cur_product.ean)

        cur_availability = retry_request(availability_check_request)
        cur_product.is_available = cur_availability
        session.commit()

    session.close()
Ejemplo n.º 6
0
                                           [test_product])

    print(result)

    test_product.asin = "B07YCSBSHX"
    test_product.price = Decimal(49.99)

    result = fees_api.get_my_fees_estimate(marketplace_id_germany,
                                           [test_product])

    print(result)

    test_product.asin = "B001B1F8WW"
    test_product.price = Decimal(4.31)

    result = fees_api.get_my_fees_estimate(marketplace_id_germany,
                                           [test_product])

    print(result)

    session = Session()

    query = session.query(ProductAmazon).filter_by(asin="B001B1F8WW")
    for cur_product in query:
        print(cur_product)
        fees_response = fees_api.get_my_fees_estimate(marketplace_id_germany,
                                                      [cur_product])
        print(fees_response)

    session.close()
Ejemplo n.º 7
0
 def __init__(self):
     self.session = Session()
Ejemplo n.º 8
0
def update_database():
    vitrex = Vitrex(
        username=settings.VITREX["USER"],
        password=settings.VITREX["PASSWORD"],
    )
    csv_string = vitrex.get_csv_string()
    csv_file = StringIO(csv_string)
    product_count = get_product_count(csv_file)
    csv_file.close()
    csv_file = StringIO(csv_string)

    logging.info("Started parsing csv")
    session = Session()
    for cur_product in tqdm(parse_csv(csv_file), total=product_count):
        old_product = (session.query(ProductWholesale).filter_by(
            shop_name=shop_name, ean=cur_product.ean).first())
        if old_product is None:
            session.add(cur_product)
            session.commit()
        elif cur_product != old_product:
            old_product.update(cur_product)
            session.commit()
    session.close()
    csv_file.close()
    logging.info("Done.")