mon_chro.py 907 B

1234567891011121314151617181920212223242526272829303132333435
  1. import sys
  2. import random
  3. import os
  4. import time
  5. import fire
  6. import dataset
  7. from datetime import datetime
  8. # import pymysql
  9. # pymysql.install_as_MySQLdb()
  10. d = ['hhh.com.tw','innews.com.tw']
  11. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  12. cursor_rank = db.query('select dt from seo.google_rank order by id desc limit 1')
  13. cursor_general = db.query('select domain from seo.general_log order by id desc limit 10')
  14. for c in cursor_rank:
  15. last_time = c['dt']
  16. diff = datetime.now() - last_time
  17. lst = []
  18. for c in cursor_general:
  19. if c['domain'] not in d:
  20. lst.append(1)
  21. if diff.seconds > 600:
  22. print('google_rank異常,啟動reboot.py')
  23. os.system('python3 reboot.py')
  24. else:
  25. print('google_rank正常')
  26. if len(lst) > 0:
  27. print('general正常')
  28. else:
  29. print('general異常,啟動reboot.py')
  30. os.system('python3 reboot.py')