def callback_toutiao(ch, method, properties, body): data = json.loads(body.decode()) logger.info("获得任务 : {}".format(data)) ch.basic_ack(delivery_tag=method.delivery_tag) did = data["id"] can = True # 校验标识 acc_flag = False # 格式处理 data["tags"] = data["tags"].split(",") data["image_path"] = data["image_path"].replace("/", "\\") data["video_path"] = data["video_path"].replace("/", "\\") # 校验 res = session.query(TdResourceAccount).get(did) #查看账户是否存在,如果不存在将无法更新cookies try: acc = session.query(TdPlatformAccount).filter( TdPlatformAccount.login_name == data['account']) acc_flag = True except Exception: pass if not res: # 判断任务是否存在 logger.error("当前任务{} 状态异常 原因: id=>{} 任务不存在 ".format(data, did)) res.remark = '任务不存在数据库中,请联系技术人员' res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if res.status != 3: # 判断状态是否允许发布 logger.error("头条任务{} 状态异常 status=> {}| ".format(did, res.status)) res.remark = "发布状态异常 status=> {}| ".format( res.status) + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if can: try: status, aid, vid, msg, cookies = ToutiaoUpload(**data).run() logger.info("当前任务{} status: {}, aid: {}, vid: {}, msg:{}".format( did, status, aid, vid, msg)) except KeyError: logger.error("任务 {} 缺少参数 消息=>{}".format(did, data)) res.remark = '任务参数传递错误' res.status = 9 re_handler.del_a_key('pubId:' + str(did)) except Exception as e: logger.error("上传未知错误 任务id:{} error=>{}".format(did, e)) res.remark = "未知错误 请检查发文日志 任务id {}".format( did) + '|' + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") res.status = 9 re_handler.del_a_key('pubId:' + str(did)) else: if not status: res.remark = '发布失败,请重新提交' res.status = 9 res.remark = msg + '|' + datetime.strftime( datetime.now(), "%Y-%m-%d %H:%M:%S") re_handler.del_a_key('pubId:' + str(did)) if acc_flag: acc.cookies = cookies else: logger.info("id: {} 发布成功".format(did)) res.remark = '发布成功' res.status = 8 res.article_id = aid res.vid = vid re_handler.del_a_key('pubId:' + str(did)) if acc_flag: acc.cookies = cookies session.commit()
def callback_dayu(ch, method, properties, body): data = json.loads(body.decode()) logger.info("获得任务 : {}".format(data)) can = True # 校验标识 acc_flag = False # 格式处理 tag_list = data["tags"].split(",") data["tags"] = data["tags"].split(",") data["image_path"] = data["image_path"].replace("/", "\\") data["video_path"] = data["video_path"].replace("/", "\\") # 查询发布状态 did = data["id"] video_type = data["video_type"] res = session.query(TdResourceAccount).get(did) try: acc = session.query(TdPlatformAccount).filter( TdPlatformAccount.login_name == data['account']) acc_flag = True except Exception: pass if not res: # 判断任务是否存在 logger.error("大鱼任务{} 状态异常 原因: id=>{} 任务不存在 ".format(data, did)) res.status = 9 res.remark = '任务不存在' re_handler.del_a_key('pubId:' + str(did)) can = False for _ in range(len(tag_list) - 1): if tag_list[_] == tag_list[_ + 1]: logger.info("标签重复,请重新提交") res.remark = '标签重复,请重新提交' res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if res.status != 3: # 判断状态是否允许发布 logger.error("大鱼任务{} 状态异常 status=> {}| ".format(did, res.status)) res.remark = "发布状态异常 status=> {}| ".format( res.status) + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") res.remark = '状态不为3,状态异常' re_handler.del_a_key('pubId:' + str(did)) res.status = 9 can = False if video_type not in vtype_set: # 判断视频类型 logger.error("大鱼任务 {} 视频类型错误 =>".format(did, video_type)) res.remark = "视频类型错误 => {}|".format(video_type) + datetime.strftime( datetime.now(), "%Y-%m-%d %H:%M:%S") res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if can: try: status, aid, vid, msg, cookies = DayuUpload(**data).run() logger.info("当前任务{} status: {}, aid: {}, vid: {}, msg:{}".format( did, status, aid, vid, msg)) except KeyError: logger.error("任务 {} 缺少参数 消息=>{}".format(did, data)) res.remark = '消息队列参数缺失' res.status = 9 re_handler.del_a_key('pubId:' + str(did)) except Exception as e: logger.error("上传未知错误 任务id:{} error=>{}".format(did, e)) res.status = 9 res.remark = "未知错误 请检查发文日志 任务id {}".format( did) + '|' + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") re_handler.del_a_key('pubId:' + str(did)) else: if not status: res.status = 9 if acc_flag: acc.cookies = cookies logger.info('发布失败 {}'.format(msg)) res.remark = '发布失败 {}'.format(msg) res.status = 9 re_handler.del_a_key('pubId:' + str(did)) else: logger.info("id: {} 发布成功".format(did)) res.remark = '发布成功' res.status = 8 res.article_id = aid res.vid = vid if acc_flag: acc.cookies = cookies re_handler.del_a_key('pubId:' + str(did)) res.publish_date = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") ch.basic_ack(delivery_tag=method.delivery_tag) session.commit()
def callback_aqy(ch, method, properties, body): data = json.loads(body.decode()) logger.info("获得任务 : {}".format(data)) can = True # 校验标识 ac_flag = False # 查询发布状态 did = data["id"] res = session.query(TdResourceAccount).get(did) try: acc = session.query(TdPlatformAccount).filter(TdPlatformAccount.login_name == data['user']).one() ac_flag = True except Exception: pass if not res: # 判断任务是否存在 logger.error("大鱼任务{} 状态异常 原因: id=>{} 任务不存在 ".format(data, did)) res.remark = '任务不存在,请联系技术人员' res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if res.status != 3: # 判断状态是否允许发布 logger.error("爱奇艺{} 状态异常 status=> {}| ".format(did, res.status)) res.remark = "发布状态异常 status=> {}| ".format(res.status) + datetime.strftime(datetime.now(),"%Y-%m-%d %H:%M:%S") res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if len(data['short_title']) > 11: logger.info("短标题不允许超过11个字符") res.remark = '短标题不允许超过11个字符' res.status = 9 can = False re_handler.del_a_key('pubId:' + str(did)) if len(data['title']) > 30: logger.info('标题不允许超过30个字符') res.remark = '标题不允许超过30个字符' res.status = 9 can = False re_handler.del_a_key('pubId:' + str(did)) if can: try: status, msg, cookies = aqy_uper(**data).main() logger.info("当前任务{} status:{} msg:{}".format(did, status, msg)) except KeyError: logger.error("任务 {} 缺少参数 消息=>{}".format(did, data)) res.remark = "缺少参数" res.status = 9 re_handler.del_a_key('pubId:' + str(did)) return except Exception as e: logger.error("上传未知错误 任务id:{} error=>{}".format(did, e)) res.status = 9 res.remark = '上传失败, 错误原因{}'.format(e) re_handler.del_a_key('pubId:' + str(did)) return if not status: print("scheduler上传失败") res.status = 9 if ac_flag: acc.cookies = cookies res.remark = '上传失败' + str(msg) re_handler.del_a_key('pubId:' + str(did)) else: logger.info("id: {} 发布成功".format(did)) logger.info("删除redis") res.remark = "发布成功" res.status = 8 re_handler.del_a_key('pubId:' + str(did)) if ac_flag: acc.cookies = cookies res.publish_date = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") session.commit() ch.basic_ack(delivery_tag=method.delivery_tag)
def callback_qutoutiao(ch, method, properties, body): try: data = json.loads(body.decode()) logger.info("获得任务 : {}".format(data)) time.sleep(300) can = True # 校验标识 # 数据处理 data["tags"] = data["tags"].split(",") data["image_path"] = data["image_path"].replace("/", "\\") data["video_path"] = data["video_path"].replace("/", "\\") did = data["id"] res = session.query(TdResourceAccount).get(did) if re_handler.get_a_key(data['account']): ch.basic_ack(delivery_tag=method.delivery_tag) ch.basic_publish(exchange='', routing_key='qutoutiao', body=body) return re_handler.set_a_key(data['account'], 'defalt') if not res: # 判断任务是否存在 logger.error("趣头条任务{} 状态异常 原因: id=>{} 任务不存在 ".format(data, did)) res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if res.status != 3: # 判断状态是否允许发布 logger.error("趣头条任务{} 状态异常 status=> {}| ".format(did, res.status)) res.remark = "发布状态异常 status=> {}| ".format( res.status) + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") res.status = 9 re_handler.del_a_key('pubId:' + str(did)) can = False if can: try: status, aid, vid, msg = QutoutiaoUpload(**data).run() logger.info( "当前任务{} status: {}, aid: {}, vid: {}, msg:{}".format( did, status, aid, vid, msg)) except KeyError: logger.error("任务 {} 缺少参数 消息=>{}".format(did, data)) res.status = 9 re_handler.del_a_key('pubId:' + str(did)) return except Exception as e: logger.error("上传未知错误 任务id:{} error=>{}".format(did, e)) res.status = 9 res.remark = "未知错误 请检查发文日志 任务id {}".format( did) + '|' + datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") re_handler.del_a_key('pubId:' + str(did)) else: if not status: res.status = 9 res.remark = '发布失败' re_handler.del_a_key('pubId:' + str(did)) else: logger.info("id: {} 发布成功".format(did)) res.remark = '发布成功' res.status = 8 res.article_id = aid res.vid = vid re_handler.del_a_key('pubId:' + str(did)) res.publish_date = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") session.commit() ch.basic_ack(delivery_tag=method.delivery_tag) re_handler.del_a_key(data['account']) except Exception as e: print(e) finally: re_handler.del_a_key(data['account'])