"""
amazon以图搜图,asin整合
"""
import pandas as pd
from db.mysql_db import get_country_engine


def get_self_asin_top():
    sql1 = f'SELECT asin, img_url, site from us_self_asin_top;'
    print(sql1)
    df_keepa_trend = pd.read_sql(sql1, con=us_engine)
    return df_keepa_trend


def get_self_asin_compet_amazon():
    sql1 = f'SELECT asin_compet as asin, img_url, site from us_self_asin_compet_amazon;'
    print(sql1)
    df_keepa_trend = pd.read_sql(sql1, con=us_engine)
    return df_keepa_trend


site = "us"
us_engine = get_country_engine(site)

top_datas = get_self_asin_top()
compet_amazon_datas = get_self_asin_compet_amazon()

compet_amazon_datas.drop_duplicates(["asin", "site"], inplace=True)

top_datas.drop_duplicates(["asin", "site"], inplace=True)

datas = pd.concat([top_datas,compet_amazon_datas],keys=['x','y'],ignore_index=True)

datas.drop_duplicates(["asin", "site"], inplace=True)

datas["state"] = 1
datas['platform'] = 'amazon'

datas.to_sql(name=f"us_self_asin_top_url", con=us_engine, if_exists='append', index=False)

