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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import requests
import pymysql
import random
import traceback
import logging
import json
import datetime
from libs.cache import redis_client
from vest.request.auto_request import get_offline_comment
from vest.request.auto_request import host, user, db, passwd
from libs.error import logging_exception
auto_reply_url = "http://saturn.iyanzhi.com/api/v1/reply/create_for_inner"
def reply(id, content, user_id):
try:
post_dict = {
'user_id': user_id,
'topic_id': id,
'content': content,
"type": 4
}
response = requests.post(url=auto_reply_url,
data=post_dict)
logging.info("response.text:%s" % response.text)
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
def get_data(now, noww):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT id,user_id FROM topic WHERE ( create_time > '%s' and create_time <= '%s' ) and is_online = 1 and content_level in (4,5,6) " % (
now, noww))
data = cursor.fetchall()
topic_id = list(data)
topic_id_list = []
for id in topic_id:
cursor.execute(
"select user_id,is_shadow from user_extra where user_id =" + str(
id[1]) + " and is_online =1 and is_deleted =0")
data = cursor.fetchall()
user_id = list(data)
if user_id and user_id[0][1] == 1:
topic_id_list.append(id)
pc.close()
logging.info("get majia topic_id_list:%s" % topic_id_list)
return topic_id_list
except:
logging.error("catch exception,get_data:%s" % traceback.format_exc())
return None
def vest_click_reply():
try:
logging.info("get majia data11111111111")
now = datetime.datetime.now()
yes_time = now - datetime.timedelta(minutes=5)
data = json.loads(redis_client.get("get_user_id_data"))
user_list = []
for i in data:
user_list.append(i[0])
topic_id = get_data(yes_time, now)
if topic_id:
for id in topic_id:
rand_num = random.randint(0, 4)
for i in range(rand_num):
num = random.randint(0, len(user_list) - 1)
user_id = user_list[num]
if user_id != id[1]:
comment_list = get_offline_comment()
comment = comment_list[i]
reply(id[0], comment, user_id)
except:
logging_exception()
logging.error("catch exception,main :%s" % traceback.format_exc())