run_ranking_day.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import sys
  2. import random
  3. import os
  4. import time
  5. import fire
  6. import dataset
  7. from random import randint
  8. #import pymysql
  9. #pymysql.install_as_MySQLdb()
  10. def run_once(pport, dockername):
  11. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  12. lst = []
  13. cursor = db.query('select term,domain from seo.selected_kw')
  14. for c in cursor:
  15. lst.append([c['term'], c['domain']])
  16. cur = db.query('select * from seo.google_rank order by id desc limit 1')
  17. count_row = db.query('select count(*) from seo.google_rank where CAST(dt AS DATE) = CAST( curdate() AS DATE)')
  18. for c in cur:
  19. kw = c['keyword']
  20. for c in count_row:
  21. now_day_len = c['count(*)']
  22. print(now_day_len)
  23. if now_day_len == 0:
  24. print('首位')
  25. intval = os.system(
  26. f'python3 ranking_day2.py get --kw="清原 中央" --domain="taroboba-yuan.com" --port="{str(pport)}"')
  27. for i in lst:
  28. if i[0] == kw:
  29. id = lst.index(i)
  30. intval = os.system(f'python3 ranking_day2.py get --kw="{lst[id+1][0]}" --domain="{lst[id+1][1]}" --port="{str(pport)}"')
  31. if intval == -1:
  32. print('-1')
  33. sys.exit()
  34. print('執行完成ranking_day2.py')
  35. class JParams(object):
  36. def get(self, port=9222):
  37. while True:
  38. try:
  39. os.system('docker container restart tiny8')
  40. time.sleep(1)
  41. run_once(9929,'tiny8')
  42. time.sleep(20)
  43. break
  44. except:
  45. os.system('docker container restart tiny9')
  46. time.sleep(15)
  47. if __name__ == '__main__':
  48. fire.Fire(JParams)