Commit 8572836f authored by 张彦钊's avatar 张彦钊

change test file

parent 69e76b94
...@@ -96,40 +96,41 @@ def write_redis(device_id,cid_list): ...@@ -96,40 +96,41 @@ def write_redis(device_id,cid_list):
print("insert redis fail") print("insert redis fail")
print(e) print(e)
def group_redis(device_id,cid_list): def group_redis(y):
# device_id = x[0] for x in y:
# cid_list = x[1] device_id = x[0]
db = pymysql.connect(host='172.16.40.158', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle') cid_list = x[1]
sql = "select b.id from src_mimas_prod_api_diary_tags a left join src_zhengxing_api_tag b " \ db = pymysql.connect(host='172.16.40.158', port=4000, user='root', passwd='3SYz54LS9#^9sBvC', db='eagle')
"on a.tag_id = b.id where b.tag_type = '3' and a.diary_id in {}".format(tuple(cid_list)) sql = "select b.id from src_mimas_prod_api_diary_tags a left join src_zhengxing_api_tag b " \
cursor = db.cursor() "on a.tag_id = b.id where b.tag_type = '3' and a.diary_id in {}".format(tuple(cid_list))
cursor.execute(sql) cursor = db.cursor()
result = cursor.fetchall()
tags = list(set([i[0] for i in result]))
if len(tags) != 0:
sql = "select a.id from src_mimas_prod_api_diary a left join src_mimas_prod_api_diary_tags b " \
"on a.id=b.diary_id left join src_zhengxing_api_tag c on b.tag_id=c.id " \
"where a.is_online = 1 and a.content_level >= '3' " \
"and c.id in {} and c.tag_type = '3'".format(tuple(tags))
cursor.execute(sql) cursor.execute(sql)
result = cursor.fetchall() result = cursor.fetchall()
cids = list(set([i[0] for i in result])) tags = list(set([i[0] for i in result]))
if len(cids) >1 : if len(tags) != 0:
r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379') sql = "select a.id from src_mimas_prod_api_diary a left join src_mimas_prod_api_diary_tags b " \
key = str(device_id) + "_dislike_diary" "on a.id=b.diary_id left join src_zhengxing_api_tag c on b.tag_id=c.id " \
if r.exists(key): "where a.is_online = 1 and a.content_level >= '3' " \
value = eval(r.get(key)) "and c.id in {} and c.tag_type = '3'".format(tuple(tags))
value.extend(cids) cursor.execute(sql)
cids = json.dumps(list(set(value))) result = cursor.fetchall()
r.set(key, json.dumps(cids)) cids = list(set([i[0] for i in result]))
else: if len(cids) >1 :
r.set(key, json.dumps(cids)) r = redis.StrictRedis.from_url('redis://:ReDis!GmTx*0aN6@172.16.40.133:6379')
r.expire(key, 60*60) key = str(device_id) + "_dislike_diary"
if r.exists(key):
value = eval(r.get(key))
def group_write(rdd): value.extend(cids)
rdd.groupByKey().foreachPartition(lambda x:x.map()) cids = json.dumps(list(set(value)))
return "good" r.set(key, json.dumps(cids))
else:
r.set(key, json.dumps(cids))
r.expire(key, 60*60)
# def group_write(rdd):
# rdd.groupByKey().foreachPartition(lambda x:x.map())
# return "good"
......
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