import requests import pymysql import random from log_settings import * import traceback import logging from auto_request import get_offline_comment from auto_request import host, user, db, passwd 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 } 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(num1, num2): 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 > '2019-05-01 00:00:00:0000' and is_shadow = 1 and content_level in (4,5,6) and id not in (select topic_id from reply where create_time > '2019-05-01 00:00:00:0000')") data = cursor.fetchall() topic_id = list(data) topic_id_list = [] for i in topic_id: cursor.execute( "select user_id from user_extra where user_id =" + str(i[1]) + " and is_shadow =1") data = cursor.fetchall() user_id = list(data) if user_id: topic_id_list.append(i) pc.close() logging.info("get topic_id_list:%s" % topic_id_list) return topic_id_list except: logging.error("catch exception,get_data:%s" % traceback.format_exc()) return None if __name__ == "__main__": try: time_list = [74387, 76585, 117069, 328935, 2798163, 2799359, 2838561, 3190754, 3209576, 3214692, 3348407, 4429049, 6382001, 6544293, 6823318, 6974054, 7237866, 7476106, 8360985, 8601578, 10221636, 10980901, 11141776, 11211574, 11211575, 11411231, 11466431, 11552668, 11653525, 11776166, 11817014, 11972230, 12097639, 12135650, 12453440, 12665859, 13257178, 13599279, 13678365, 14080451, 14157850, 14163222, 14500068, 14555043, 14558956, 14681127, 14690417, 15039277, 15049537, 15073185, 15285940, 15291098, 15298748, 15971036, 16700794, 17477389, 17628547, 17767124, 17773384, 17830042, 18051752, 18055628, 18251036, 18287093, 18308791, 18428002, 18428020, 22744622, 24983861, 31295552, 33418748, 36479190, 36490317, 36578294, 36578342, 37016057, 37163478, 37172979, 37173148, 37173238, 39903458, 41417795, 42366771, 42682900, 42683325, 44614403, 44629365, 44652089, 44653148, 44654235, 45467976, 45852874, 45910310, 45978527, 46613768, 46614254, 46614302, 46614304, 46614371, 46614566, 46614568, 46614570, 46614589, 46614601, 46614603, 46614652, 46614654, 46614655, 46614665, 46614666, 46614676, 46614677, 46614678, 46614704, 46614715, 46614734, 46614745, 46614750, 46614763, 46614806, 46614811, 46614814, 46614844, 46614867, 46614953, 46614974, 46615298, 46615303, 46615444, 46615448, 46615692, 46615806, 46615811, 46615814, 46615819, 46615820, 46615822, 46615825, 46615826, 46616125, 46616141, 46616144, 46616146, 46616148, 46616150, 46616153, 46616158, 46616159, 46616161, 46616169, 46616173, 46616177, 46616179, 46616180, 46616182, 46616186, 46616187, 46616188, 46616209, 46616212, 46616233, 46616235, 46616237, 46616242, 46616250, 46616256, 46616262, 46616276, 46616345, 46616361, 46616522, 46618060, 46618369, 46618394, 46618454, 46618666, 46618675, 46618680, 46618683, 46618701, 46618708, 46618710, 46618740, 46618752, 46618755, 46618792, 46618800, 46618816, 46618818, 46618819, 46618826, 46618830, 46619562, 46619756, 46619871, 46620004, 46620025, 46620029, 46620039, 46620043, 46620046, 46620055, 46620059, 46620064, 46620070, 46620073, 46620098, 46620107, 46620121, 46620135, 46620146, 46620149, 46620163, 46620175, 46620178, 46620181, 46620191, 46620194, 46620196, 46628317, 46628364, 46628365, 46628367, 46628371, 46628372, 46628420, 46628425, 46628535, 46628566, 46628573, 46628575, 46628580, 46628583, 46628585, 46628587, 46628592, 46628593, 46628594, 46628595, 46628596, 46628600, 46628601, 46628602, 46628605, 46628606, 46628607, 46628608, 46628609, 46628611, 46628612, 46628614, 46628615, 46628616, 46628617, 46628619, 46628620, 46628622, 46628624, 46628627, 46628628, 46628630, 46628635, 46628637, 46628638, 46628640, 46628644, 46628646, 46628648, 46628649, 46628652, 46628654, 46628655, 46628656, 46628658, 46628659, 46628660, 46628662, 46628667, 46628668, 46628669, 46628670, 46628673, 46628680, 46628681, 46628682, 46628683, 46628685, 46628687, 46628688, 46628690, 46628691, 46628695, 46628697, 46628698, 46628700, 46628704, 46628708, 46628709, 46628710, 46628711, 46628712, 46628713, 46628714, 46628715, 46628717, 46628718, 46628721, 46628723, 46628728, 46628731, 46628732, 46628734, 46628736, 46628738, 46628739, 46628742, 46628743, 46628745, 46628746, 46628748, 46628750, 46628751, 46628752, 46628753, 46628755, 46628756, 46628757, 46628758, 46628760, 46628761, 46628764, 46628766, 46628770, 46628773, 46628774, 46628775, 46628779, 46628780, 46628781, 46628783, 46628790, 46628795, 46628796, 46628799, 46628800, 46628801, 46628802, 46628803, 46628805, 46628808, 46628810, 46628812, 46628817, 46628820, 46628823, 46628824, 46628828, 46628829, 46628835, 46628836, 46628838, 46628839, 46628844, 46628845, 46628846, 46628849, 46628852, 46628854, 46628855, 46628856, 46628858, 46628859, 46628863, 46628864, 46628867, 46628868, 46628874, 46628875, 46628878, 46628880, 46628881, 46628882, 46628885, 46628890, 46628895, 46628896, 46628898, 46628900, 46628901, 46628905, 46628913, 46628928, 46628929, 46628933, 46628939, 46628940, 46628942, 46628943, 46628944, 46628955, 46628956, 46628961, 46628962, 46628963, 46628965, 46628966, 46628971, 46628973, 46628974, 46628976, 46628977, 46628978, 46628979, 46628980, 46628984, 46628987, 46628991, 46628993, 46628995, 46628998, 46629000, 46629003, 46629006, 46629007, 46629008, 46629009, 46629010, 46629011, 46629012, 46629014, 46629016, 46629017, 46629020, 46629022, 46629024, 46629031, 46629032, 46629033, 46629039, 46629042, 46629043, 46629046, 46629048, 46629052, 46629053, 46629057, 46629059, 46629079, 46629085, 46629097, 46629105, 46629106, 46629107, 46629108, 4662911346629114, 46629117, 46629118, 46629120, 46629128, 46629130, 46629131, 46629132, 46629134, 46629135, 46629137, 46629139, 46629140, 46629142, 46629144, 46629147, 46629149, 46629150, 46629152, 46629153, 46629155, 46629156, 46629157, 46629161, 46629163, 46629164, 46629170, 46629171, 46629172, 46629175, 46629176, 46629182, 46629184, 46629186, 46629188, 46629189, 46629192, 46629193, 46629199, 46629201, 46629203, 46629204, 46629205, 46629207, 46629211, 46629212, 46629213, 46629218, 46629220, 46629224, 46629225, 46629226, 46629227, 46629229, 46629230, 46629232, 46629233, 46629234, 46629239, 46629243, 46629252, 46629264, 46629270, 46629274, 46629278, 46629285, 46629295, 4662930446629305, 46629309, 46629313, 46629329, 46629334, 46629338, 46629339, 46629358, 46629374, 46629385, 46629416, 46629419, 46629424, 46629683, 46629740, 46629782, 46629804, 46629820, 46629877, 46630485] user_data = open("/data/log/cybertron/app/user_id.txt", "r") user_list = [] for i in user_data.readlines(): user_list.append(i) dicts = {} for id in time_list: dicts = {} rand_num = random.randint(0, 3) for i in range(rand_num): num = random.randint(0, len(user_list) - 1) user_id = user_list[num] comment_list = get_offline_comment() comment = comment_list[i] logging.info("get id :%s" % id) reply(id, comment, user_id) except: logging.error("catch exception,main :%s" % traceback.format_exc())