mon_chro.py 502 B

1234567891011121314151617181920
  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. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  11. cursor = db.query('select dt from seo.google_rank order by id desc limit 1')
  12. for c in cursor:
  13. last_time = c['dt']
  14. diff = datetime.now() - last_time
  15. if diff.seconds > 600:
  16. print('異常,啟動reboot.py')
  17. os.system('python3 reboot.py')
  18. print('正常')