notify_nda.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import time
  2. import json
  3. from selenium import webdriver
  4. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  5. import time
  6. import os
  7. import re
  8. import urllib.parse
  9. from selenium.webdriver.support.ui import WebDriverWait
  10. from selenium.webdriver.common.by import By
  11. from selenium.webdriver.support import expected_conditions as EC
  12. import codecs
  13. import random
  14. import requests
  15. import dataset
  16. import time
  17. import sys
  18. import docker
  19. import dataset
  20. import pymysql
  21. pymysql.install_as_MySQLdb()
  22. headers = {
  23. "Authorization": "Bearer " + "OZDcq7sVKwr3F6YNLtBF3LuIgpa4Ql9eAnBWeD7sHTJ",
  24. "Content-Type": "application/x-www-form-urlencoded"
  25. }
  26. def send_msg(kw):
  27. params = {"message": kw}
  28. print('通知結果', params)
  29. r = requests.post("https://notify-api.line.me/api/notify", headers=headers, params=params)
  30. # db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  31. db = dataset.connect('postgresql://postgres:eyJhbGciOiJI@172.105.241.163:5432/postgres')
  32. # cursor = db.query('SELECT * FROM seo.nda_log where datediff(now(),dt)=0 order by dt desc')
  33. cursor = db.query('SELECT * FROM public.seo_jobs_ranking where CAST(avg_neg AS numeric) = 0 and now()::date = dt::date')
  34. result = "\n"
  35. idx = 0
  36. lst = []
  37. result = ""
  38. for c in cursor:
  39. lst.append(c['kw'])
  40. result+=f"{c['kw']}\n"
  41. msg_per_total_click = '\n分數等於0分的關鍵字:\n' + result
  42. print(msg_per_total_click)
  43. msg = "\n機器人執行次數:" + str(idx)
  44. # print(msg_per_total_click + result + sns_per_total_click + sns_result + ga_sessions)
  45. send_msg(msg_per_total_click)
  46. db.close()
  47. # schtasks /create /sc minute /mo 30 /sd 2022/05/050 /st 9:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"
  48. SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
  49. sys.path.append(os.path.dirname(SCRIPT_DIR))