run_sheet_hhh.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import sys
  2. import codecs
  3. import traceback
  4. import requests
  5. import re
  6. import pandas as pd
  7. import random
  8. import urllib
  9. import json
  10. import gspread
  11. import datetime
  12. from gspread_pandas import Spread, Client
  13. from oauth2client.service_account import ServiceAccountCredentials
  14. import os
  15. import redis
  16. import time
  17. import fire
  18. import dataset
  19. #import pymysql
  20. #pymysql.install_as_MySQLdb()
  21. def run_once(pport, dockername):
  22. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  23. lst = []
  24. cursor = db.query('SELECT * FROM hhh.seo_designer')
  25. for c in cursor:
  26. lst.append([c['kw']])
  27. obj = random.choice(lst)
  28. print(obj)
  29. kw = obj[0]
  30. domain = 'hhh.com.tw'
  31. print(kw,domain)
  32. s = f'python3 general_clickbot_hhh.py get --kw="{kw}" --domain="{domain}" --port={str(pport)}'
  33. intval = os.system(f'python3 general_clickbot_hhh.py get --kw="{kw}" --domain="{domain}" --port="{str(pport)}"')
  34. print('執行genetal_clickbot')
  35. if intval == -1:
  36. print('-1')
  37. sys.exit()
  38. class JParams(object):
  39. def get(self, port=9222):
  40. while True:
  41. try:
  42. os.system('docker container restart tiny5')
  43. time.sleep(1)
  44. run_once(9926, 'tiny5')
  45. time.sleep(20)
  46. break
  47. except:
  48. os.system('docker container restart tiny5')
  49. time.sleep(15)
  50. if __name__ == '__main__':
  51. fire.Fire(JParams)