瀏覽代碼

run_sheet_2

zooeytsai 2 年之前
父節點
當前提交
78421d724e
共有 1 個文件被更改,包括 64 次插入0 次删除
  1. 64 0
      INNNews/run_sheet_2.py

+ 64 - 0
INNNews/run_sheet_2.py

@@ -0,0 +1,64 @@
+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)
+