run_ball.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import time
  2. import os
  3. from apscheduler.schedulers.background import BackgroundScheduler
  4. from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
  5. def zhibo():
  6. os.system("scrapy crawl zhibo")
  7. def roll_ball():
  8. os.system("scrapy crawl roll_lanqiu")
  9. os.system("scrapy crawl roll_wangqiu")
  10. os.system("scrapy crawl roll_bangqiu")
  11. os.system("scrapy crawl roll_zuqiu")
  12. os.system("scrapy crawl jieshu")
  13. def ball():
  14. os.system("scrapy crawl lanqiu")
  15. os.system("scrapy crawl bangqiu")
  16. os.system("scrapy crawl wangqiu")
  17. os.system("scrapy crawl zuqiu")
  18. def other():
  19. os.system("scrapy crawl guanjun")
  20. os.system("scrapy crawl saiguo")
  21. def kill_ball():
  22. os.system("ps -ef | grep scrapy | grep -v grep | cut -c 9-15 | xargs kill -9")
  23. if __name__ == "__main__":
  24. executors = {
  25. 'default': ThreadPoolExecutor(20),
  26. 'processpool': ProcessPoolExecutor(5)
  27. }
  28. scheduler = BackgroundScheduler(executors=executors)
  29. # 每20分钟执行一次
  30. scheduler.add_job(zhibo, 'interval', seconds=5)
  31. scheduler.add_job(roll_ball, 'interval', seconds=30)
  32. scheduler.add_job(ball, 'interval', minutes=3)
  33. scheduler.add_job(other, 'interval', minutes=30)
  34. scheduler.add_job(kill_ball, 'interval', minutes=150)
  35. scheduler.start()
  36. print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
  37. try:
  38. while True:
  39. time.sleep(2)
  40. except (KeyboardInterrupt, SystemExit):
  41. scheduler.shutdown()