import requests
from search.abSearch import totalrun
from tools import *
from tools.publicFun import genUuidDeviceid
from tools.fileOperation import *
def sendhttp(url,header=None,body=None,methodtype='get'):
    if methodtype=='get':
        rep=requests.request(url=url,method=methodtype,headers=header,params=body)
    else:
        rep=requests.request(url=url,method=methodtype,headers=header,data=body)
    return rep.json()

def sendfeed(uuid):
    '''
    :param uuid:
    :return: 触发feed流召回，即appstart-topic
    '''
    uuid,deviced=genUuidDeviceid()
    url="http://aws-online-recommend-parent.ec-test.qg-rc.net/recommend/hodgepodge_stream?deviceId={}" \
        "&userUuid={}&unionItemType=product_jd&pageSize=20&pageType=2&ip=192.168.28.142".format(uuid,deviced)
    t=sendhttp(url)
    return t

def sendsearch(isFirstPage=1):
    '''
    :param isFirstPage:
    :return: 触发搜索召回
    '''
    t=totalrun(isFirstPage=isFirstPage)
    return t

def sendhit(skuno,namespace):
    '''
    :param isFirstPage:
    :return: 触发相似推荐召回，即：点击topic
    '''
    k={'sku_no':skuno}
    sql=concatSql(skuinfo_sql,**k)
    skuinfo=execmysl(namespace,sql)
    if skuinfo.empty:
        raise Exception('skuno[{}]不存在'.format(skuno))
    uuid,deviced=genUuidDeviceid()
    skutype=skuinfo['source_type'].to_list()[0]
    url="http://172.20.1.131:23060/recommend/similarity_products?sourceId={}&appVersion=8.7.00" \
        "&gid={}&sourceType={}&ip=192.168.29.228" \
        "&channel=159913&userUuid={}&pageSize=20" \
        "&parentPageType=&terminal=MINI-APP".format(skuno,deviced,skutype,uuid)
    t=sendhttp(url)
    return t


if __name__ == '__main__':
    print(sendsearch(isFirstPage=1))


