import sys import codecs import traceback import requests import re import pandas as pd import random import urllib import json import gspread import datetime from gspread_pandas import Spread, Client from oauth2client.service_account import ServiceAccountCredentials import os import redis import time import fire def run_once(pport, dockername): r = redis.Redis(host='db.ptt.cx', port=6379, db=1, password='choozmo9') js = r.get('innews_sheet') jsobj = json.loads(js) kw = random.choice(jsobj) # 第一次(三組關鍵字) kw_innews = '引新聞 ' # 第二次(隨機選擇兩組關鍵字與引新聞) num = random.choices([0, 1, 2], k=2) for i in num: kw_innews += kw['kw'].split(' ')[i] + ' ' print(kw) intval = os.system( 'python general_clickbot_local.py get --kw="' + kw['kw'] + '" --domain=innews.com.tw --port=' + str(pport)) print('等待') print(intval) if intval == -1: print('-1') sys.exit() class JParams(object): def get(self, port=9222): print(port) while True: try: os.system('docker container restart tiny1') # os.system('docker container restart tiny2') # os.system('docker container restart tiny3') time.sleep(1) run_once(9922, 'tiny1') # run_once(9923, 'tiny2') # run_once(9924, 'tiny3') time.sleep(20) except: os.system('docker container restart tiny1') time.sleep(15) if __name__ == '__main__': fire.Fire(JParams)