1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pymysql
import traceback
import logging
import json
from vest.request.auto_request import logins, time_convs, get_answer_data, reply_answer, get_majia, \
set_reply_to_redis
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
import random
def get_data(numtime, numtime2):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT user_id,id FROM topic WHERE is_online=1 and (create_time >= '%s' and create_time <= '%s' )" % (
numtime2, numtime))
data = cursor.fetchall()
topic_id_list = list(data)
return topic_id_list
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return []
def answer_reply5():
try:
logging.info("comment answer five")
numtime1, numtime2 = time_convs(5, 5)
user_id = get_data(numtime1, numtime2)
redis_key = "cybertron:set_reply_id:five"
reply_data_comment = []
if user_id:
for i in user_id:
random_num = random.randint(0, 2)
logging.info("get random_num:%s" % random_num)
for num in range(random_num):
majia_user_id = get_majia()
cook = logins(majia_user_id)
comment1, comment2 = get_answer_data()
if cook is not None:
response = reply_answer(cook, i[1], comment1)
if len(response) > 1:
data_dict = json.loads(response)
reply_id = data_dict["data"]["id"]
reply_user_id = data_dict["data"]["user"]["id"]
reply_data_comment.append(
{"id": reply_id, "reply_user_id": reply_user_id, "answer": comment2, "topic_id": i[1],
"majia_user_id": majia_user_id})
redis_client = set_reply_to_redis()
redis_client.set(redis_key, json.dumps(reply_data_comment))
except:
logging_exception()
logging.error("catch exception,main:%s" % traceback.format_exc())