import sys import random import os import time import fire import dataset from random import randint #import pymysql #pymysql.install_as_MySQLdb() def run_once(pport, dockername): db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4') lst = [] cursor = db.query('select term,domain from seo.selected_kw') for c in cursor: lst.append([c['term'], c['domain']]) cur = db.query('select * from seo.google_rank order by id desc limit 1') count_row = db.query('select count(*) from seo.google_rank where CAST(dt AS DATE) = CAST( curdate() AS DATE)') for c in cur: kw = c['keyword'] for c in count_row: now_day_len = c['count(*)'] print(now_day_len) if now_day_len == 0: print('首位') intval = os.system( f'python3 ranking_day2.py get --kw="清原 中央" --domain="taroboba-yuan.com" --port="{str(pport)}"') for i in lst: if i[0] == kw: id = lst.index(i) intval = os.system(f'python3 ranking_day2.py get --kw="{lst[id+1][0]}" --domain="{lst[id+1][1]}" --port="{str(pport)}"') if intval == -1: print('-1') sys.exit() print('執行完成ranking_day2.py') class JParams(object): def get(self, port=9222): while True: try: os.system('docker container restart tiny8') time.sleep(1) run_once(9929,'tiny8') time.sleep(20) break except: os.system('docker container restart tiny9') time.sleep(15) if __name__ == '__main__': fire.Fire(JParams)