run_video_account_crawler.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """
  2. @author: luojunhui
  3. 执行视频&&账号的抓取
  4. """
  5. import traceback
  6. from datetime import datetime
  7. from argparse import ArgumentParser
  8. from applications import bot
  9. from coldStartTasks.crawler import WeixinAccountCrawler, WeixinVideoCrawler
  10. account_crawler = WeixinAccountCrawler()
  11. video_crawler = WeixinVideoCrawler()
  12. def main():
  13. """
  14. 主函数
  15. :return:
  16. """
  17. parser = ArgumentParser()
  18. parser.add_argument("--run-date",
  19. help="Run only once for date in format of %Y%m%d. \
  20. If no specified, run as daily jobs.")
  21. args = parser.parse_args()
  22. if args.run_date:
  23. run_date = datetime.strptime(args.run_date, "%Y-%m-%d")
  24. print("Run in manual mode. Date: {}".format(args.run_date))
  25. else:
  26. run_date = datetime.today()
  27. # # 先执行账号抓取
  28. # try:
  29. # account_crawler.run(run_date)
  30. # except Exception as e:
  31. # error_msg = traceback.format_exc()
  32. # bot(
  33. # title='账号抓取v1执行失败',
  34. # detail={
  35. # "error": str(e),
  36. # "traceback": error_msg
  37. # }
  38. # )
  39. # 再执行文章抓取
  40. try:
  41. video_crawler.run()
  42. except Exception as e:
  43. error_msg = traceback.format_exc()
  44. bot(
  45. title='视频抓取执行失败',
  46. detail={
  47. "error": str(e),
  48. "traceback": error_msg
  49. }
  50. )
  51. # 再执行账号抓取v2
  52. try:
  53. account_crawler.run_v2()
  54. except Exception as e:
  55. error_msg = traceback.format_exc()
  56. bot(
  57. title='账号抓取V2执行失败',
  58. detail={
  59. "error": str(e),
  60. "traceback": error_msg
  61. }
  62. )
  63. if __name__ == '__main__':
  64. main()