run_gsrack.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 seo.selected_kw where client="神助物流"')
  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_gsrack.py get --kw="{kw}" --domain="{domain}" --port={str(pport)}'
  33. intval = os.system(f'python3 general_gsrack.py get --kw="{kw}" --domain="{domain}" --port="{str(pport)}"')
  34. print('執行genetal_gsrack')
  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 tiny9')
  43. time.sleep(10)
  44. run_once(9928, 'tiny9')
  45. except:
  46. os.system('docker container restart tiny9')
  47. time.sleep(15)
  48. if __name__ == '__main__':
  49. fire.Fire(JParams)