123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- """
- @author: luojunhui
- """
- import datetime
- import traceback
- from applications import longArticlesMySQL, bot
- from coldStartTasks.crawler.weixinCategoryCrawler import weixinCategory
- from coldStartTasks.publish.publishCategoryArticles import CategoryColdStartTask
- DEFAULT_CATEGORY_LIST = ['1030-手动挑号']
- class AccountColdStartDailyTask(object):
- """
- 账号冷启动代码
- """
- def __init__(self):
- """
- """
- self.db_client = None
- def init_db(self):
- """
- 初始化数据库
- :return:
- """
- try:
- self.db_client = longArticlesMySQL()
- return True
- except Exception as e:
- bot(
- title='账号抓取任务, 冷启动数据库连接失败',
- detail={
- "error": str(e),
- "error_msg": traceback.format_exc()
- }
- )
- return False
- def crawler_task(self, category_list):
- """
- :return:
- """
- # 初始化category抓取类
- try:
- weixin_category_crawler = weixinCategory(db_client=self.db_client)
- weixin_category_crawler.deal(category_list=category_list)
- bot(
- title="账号冷启动任务,抓取完成",
- detail={
- "finish_time": datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S'),
- "category": category_list
- },
- mention=False
- )
- except Exception as e:
- bot(
- title="账号抓取冷启动任务,抓取失败",
- detail={
- "error": str(e),
- "error_msg": traceback.format_exc()
- }
- )
- def publish_task(self, category_list):
- """
- 将账号文章发布到aigc抓取计划,并且绑定生成计划
- :param category_list:
- :return:
- """
- try:
- weixin_category_publisher = CategoryColdStartTask(db_client=self.db_client)
- weixin_category_publisher.do_job(
- category_list=category_list
- )
- bot(
- title="账号冷启任务,发布完成",
- detail={
- "finish_time": datetime.datetime.today().strftime('%Y-%m-%d %H:%M:%S'),
- "category": category_list
- },
- mention=False
- )
- except Exception as e:
- bot(
- title="账号发布冷启动任务,抓取失败",
- detail={
- "error": str(e),
- "error_msg": traceback.format_exc()
- }
- )
- def main(category_list=None):
- """
- main job, use crontab to do job daily
- todo: 1. 开放一个输入可以输入指定品类 2. 增加对指定账号的抓取&&发布
- :return:
- """
- if not category_list:
- category_list = DEFAULT_CATEGORY_LIST
- task = AccountColdStartDailyTask()
- if task.init_db():
- task.crawler_task(category_list=category_list)
- task.publish_task(category_list=category_list)
- if __name__ == '__main__':
- main()
|