from recommend import *

def feed_data(uuid):
    ##获取实时cid3
    cid3_dict={}
    cid3_list=[]
    online_feature_change_redis=online_feature_redis.format(uuid).strip()
    online_cid3=getRedisValue('89',online_feature_change_redis)
    online_cid3_temp=json.loads(online_cid3.get(online_feature_change_redis)) if online_cid3 else 0
    cid3_online_real=online_cid3_temp.get('user_latest_cid3_intention_today')
    cid3_dict['online_cid3']=cid3_online_real
    cid3_temp=online_cid3_temp.get('user_all_intention_cid3_count_with_timestamp_today')
    print("---",cid3_temp)
    for k,v in cid3_temp.items():
        if v.get('count')>=5:
            cid3_list.append(k)
    if cid3_list:
        #print(cid3_list,cid3_online_real)
        #cid3_list.remove(cid3_online_real) if cid3_list.index(cid3_online_real) else 0
        cid3_dict['offline_cid3']=cid3_list
    else:
    ##获取长期cid3
        offline_cid3=getRedisValue('89',offline_feature_redis)
        offline_cid3_temp=offline_cid3.get(offline_feature_redis.strip()) if offline_cid3 else []
        cid3_offline_real=offline_cid3_temp.get(uuid)
        cid3_dict['offline_cid3']=removeRepeat(cid3_offline_real.append(cid3_online_real))
    return cid3_dict

def dapan(remove_cid3_list):
    dapan_change_sql=concatSql(dapan_sql,**{"cid3":remove_cid3_list,"oper":"not"}) +" order by all_rank limit 100"
    dapan_df=execmysl('89',dapan_change_sql)
    return dapan_df.drop_duplicates(['cid3'])['cid3'].to_list()[:5]

def main(uuid):
    online_offline_result=feed_data(uuid)
    print(online_offline_result)
    cid3_list=removeRepeat(str(online_offline_result.get('online_cid3')).split()+online_offline_result.get('offline_cid3'))
    dapan_temp=dapan(cid3_list)
    print(cid3_list)
    print(dapan_temp)




if __name__ == '__main__':
    #t=dapan([1,2])
    #print(t)
    #print(feed_data('54ad92ae-d1f1-4dad-a001-38904248fba5'))
    print(main('54ad92ae-d1f1-4dad-a001-38904248fba5'))

