Commit e00229dd authored by 张彦钊's avatar 张彦钊

增加批量从数据库查询数据

parent 6ff78a67
......@@ -8,6 +8,7 @@ import utils
import warnings
from multiprocessing import Pool
from config import *
import time
def test_con_sql(device_id):
......@@ -125,27 +126,33 @@ def save_result(queue_name, x_list):
def merge_score(x_list, score_df):
db = pymysql.connect(host='10.66.157.22', port=4000, user='root',passwd='3SYz54LS9#^9sBvC', db='eagle')
cursor = db.cursor()
print("连接蔡成功")
score_list = []
# 去除diary_id 前面的"diary|"
x_list = list(map(lambda x:x[6:],x_list))
for i in x_list:
sql = "select score from biz_feed_diary_score where diary_id = '{}';".format(i)
cursor.execute(sql)
if cursor.execute(sql) != 0:
result = cursor.fetchone()[0]
score_list.append(result)
print("成功获取")
# 没有查到这个diary_id,默认score值是0
else:
print("结果是空")
score_list.append(0)
start = time.time()
db.close()
sql = "select score from biz_feed_diary_score where diary_id in '{}';".format(tuple(x_list))
cursor.execute(sql)
result = cursor.fetchall()
score_list = list(result)
#score_list = []
# for i in x_list:
# sql = "select score from biz_feed_diary_score where diary_id = '{}';".format(i)
# cursor.execute(sql)
# if cursor.execute(sql) != 0:
# result = cursor.fetchone()[0]
# score_list.append(result)
# print("成功获取")
# # 没有查到这个diary_id,默认score值是0
# else:
# print("结果是空")
# score_list.append(0)
db.close()
end = time.time()
score_df["score"] = score_df["score"] + score_list
print("done merge")
print("更新分数耗时:{}分".format((end-start)/60))
update_dairy_queue(score_df)
......@@ -169,11 +176,13 @@ def update_dairy_queue(score_df):
for j in video_id:
diary_id.insert(i, j)
i += 5
print("排序成功1")
return diary_id
else:
score_df = score_df.sort_values(by="score", ascending=False)
print("排序成功2")
return score_df["cid"].values.tolist()
print("排序成功")
def update_sql_dairy_queue(queue_name, diary_id):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment