run_sheet_local.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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():
  22. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  23. lst = ['倉儲管理 神助移動貨架','倉儲管理 神助貨架','倉儲 管理']
  24. # cursor = db.query('select term, domain from seo.selected_kw where client="仁本"')
  25. # for c in cursor:
  26. # lst.append([c['term'], c['domain']])
  27. obj = random.choice(lst)
  28. kw = obj
  29. domain = 'jiatetea.tw'
  30. print(kw, domain)
  31. os.chdir('/Users/zooeytsai/kw_tools/INNNews')
  32. intval = os.system(f'python3 general_clickbot_local.py get --kw="{kw}" --domain="{domain}"')
  33. print('執行完成genetal_clickbot')
  34. if intval == -1:
  35. print('-1')
  36. sys.exit()
  37. db.close()
  38. def run_specific():
  39. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  40. # db_local = dataset.connect('mysql://root:jondae350@localhost/ig_tags')
  41. lst = []
  42. # cursor = db.query('select term, domain from ig_tags.select_kw where client="班尼斯口碑"')
  43. # for c in cursor:
  44. # lst.append([c['term'], c['domain']])
  45. # obj = random.choice(lst)
  46. # kw = obj[0]
  47. kw_list = ['倉儲 管理']
  48. kw = random.choice(kw_list)
  49. # domain = obj[1]
  50. domain = 'gs-rack.com'
  51. print(kw, domain)
  52. os.chdir('/Users/zooeytsai/kw_tools/INNNews')
  53. intval = os.system(f'python3 general_clickbot_local.py get --kw="{kw}" --domain="{domain}"')
  54. print('執行完成genetal_clickbot')
  55. if intval == -1:
  56. print('-1')
  57. sys.exit()
  58. db.close()
  59. while True:
  60. # run_once()
  61. run_specific()
  62. time.sleep(random.randint(120,150))