def sql_in(mub, name, like, nub, date, author):
    obj = get_mysql.SqlHelper()
    file_id = ''
    if nub == 15:
        print('名片,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
    if nub == 4:
        print('挂件,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
    if nub == 3:
        print('主题,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
    if nub == 2:
        print('气泡,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
    if nub == 23:
        print('头像,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
    if nub == 8:
        print('背景,%s,%s,%s,id%s,时间%s' % (name, like, author, mub, date))
        file_id = Get_file_id(mub)
    try:
        obj.modify(
            'INSERT INTO tenxun_preview(tenxun_id,tenxun_name,likes,type,date ,author,file_id) VALUES (%s,%s,%s,%s,%s,%s)',
            [mub, name, like, nub, date, author, file_id])
        print('提交正常')
    except Exception as e:
        print(e)
        print(date)
        obj.modify(
            'UPDATE tenxun_preview SET likes = %s , date = %s,tenxun_name = %s,file_id = %s WHERE tenxun_id = %s and type = %s',
            [like, date, name, file_id, mub, nub])
        print('更新正常')
    obj.close()
def Get_Business_Id():
    obj = get_mysql.SqlHelper()
    author_name = obj.get_list(
        'SELECT author FROM `tenxun_preview` GROUP BY author', [])
    for i in author_name:
        print(i['author'])
        tenxun_nub = obj.get_one(
            "SELECT tenxun_id,type FROM `tenxun_preview` WHERE author = %s", [
                i['author'],
            ])
        print(tenxun_nub)
        try:
            product_url = 'https://zb.vip.qq.com/v2/pages/itemDetail?appid=%s&itemid=%s&_nav_titleclr=000000&_nav_txtclr=000000' % (
                tenxun_nub['type'], tenxun_nub['tenxun_id'])
            product_re = requests.get(url=product_url, headers=Headers)
            tenxun_business_id = re.findall('productId":([0-9]*)',
                                            product_re.text, re.S)[0]
            tenxun_business_name = re.findall(
                'ata-v-4c6112a2>由(.*)提供&gt;</span></p><', product_re.text,
                re.S)[0]
            try:
                obj.modify(
                    'INSERT INTO tenxun_business(tenxun_business_id,tenxun_business_name) VALUES(%s,%s)',
                    [tenxun_business_id, tenxun_business_name])
            except Exception as e:
                print(e)
            print(tenxun_business_id, tenxun_business_name)
            print('--------------------------------------------------------')
        except Exception as e:
            print(e)
    obj.close()
def get_sql_update(id_tenxun, like):
    '''主题:1
       气泡:2'''
    obj = get_mysql.SqlHelper()
    print(id_tenxun, like)
    obj.modify('UPDATE tenxun_preview SET likes = %s WHERE tenxun_id = %s',
               [like, id_tenxun])
    obj.close()
def get_sql(id_tenxun, name, like, type, author):
    '''主题:1   3
       气泡:2
       名片:3   15
       挂件:4
       背景:8'''
    obj = get_mysql.SqlHelper()
    obj.modify(
        'INSERT INTO tenxun_preview(tenxun_id,tenxun_name,likes,type,author) VALUES (%s,%s,%s,%s,%s)',
        [id_tenxun, name, like, type, author])
    obj.close()
headers = {
    'user-agent':
    'Mozilla/5.0 (Linux; Android 6.0; vivo Y67A Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045008 Mobile Safari/537.36 V1_AND_SQ_8.3.3_1376_YYB_D QQ/8.3.3.4515 NetType/WIFI WebP/0.3.0 Pixel/720 StatusBarHeight/49 SimpleUISwitch/0 QQTheme/1000',
    # 'cookie':str(denglu)
    'cookie':
    'ptcz=524226d2afe911330fbfb452ece92c88adaf537005227086da273eb7e9063cd5; pgv_pvi=2405019648; RK=8qQlllsT7n; pgv_pvid=6010152923; ts_refer=ui.ptlogin2.qq.com/; ts_uid=5448687400; uin=o0657110547; skey=@shjwX0QAr; p_uin=o0657110547; pt4_token=Zs-NE*oJJhRTQEmFDl3j-atzbKB0cp9T8fQiB3nAXvw_; p_skey=rN-gkfP8hZoufjX8eHT9nHUITiB5QRgqA6cQYFY1nX0_; pgv_info=ssid=s5485149412; ts_last=zb.vip.qq.com/v2/pages/itemDetail',
    'referer':
    'https://zb.vip.qq.com/v2/pages/itemDetail?appid=2&itemid=10871&_nav_titleclr=000000&_nav_txtclr=000000',
    'sec-fetch-site': 'same-origin',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'zh-CN,zh;q=0.9',
}
obj = get_mysql.SqlHelper()
'''链接数据库'''


def get_sql(id_tenxun, name, like, type, author):
    '''主题:1   3
       气泡:2
       名片:3   15
       挂件:4
       背景:8'''
    obj = get_mysql.SqlHelper()
    obj.modify(
        'INSERT INTO tenxun_preview(tenxun_id,tenxun_name,likes,type,author) VALUES (%s,%s,%s,%s,%s)',
        [id_tenxun, name, like, type, author])
    obj.close()