seo_notify.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import redis
  2. import time
  3. import json
  4. from selenium import webdriver
  5. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  6. import time
  7. import os
  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. from bs4 import BeautifulSoup
  15. import requests
  16. import dataset
  17. import time
  18. import rpyc
  19. import sys
  20. import docker
  21. import pymysql
  22. pymysql.install_as_MySQLdb()
  23. <<<<<<< HEAD
  24. from ga_click import main
  25. =======
  26. from monitor.ga_click import main
  27. >>>>>>> 604b4f0737fe7f055de28e84a0a4697a346701cf
  28. headers = {
  29. "Authorization": "Bearer " + "OZDcq7sVKwr3F6YNLtBF3LuIgpa4Ql9eAnBWeD7sHTJ",
  30. "Content-Type": "application/x-www-form-urlencoded"
  31. }
  32. name = {'beastparadise.net':'毛怪','taroboba-yuan.com':'清原','match-planet.com':'火柴星人','hhh.com.tw':['幸福空間','幸福空間設計師'],'sctt.com.tw':'仁本'}
  33. def send_msg(kw):
  34. params = {"message": kw}
  35. print('通知結果', params)
  36. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  37. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
  38. cursor = db.query(
  39. 'SELECT * FROM seo.general_log where domain != "innews.com.tw" and datediff(now(),dt)=0 order by dt desc')
  40. cursor_rank = db.query(
  41. 'SELECT * FROM seo.google_rank where datediff(now(),dt)=0 order by dt desc')
  42. result = "\n"
  43. idx = 0
  44. d = {'beastparadise.net':0,'match-planet.com':0,'taroboba-yuan.com':0,'hhh.com.tw':0,'sctt.com.tw':0,'hhh.com.tw/designer':0}
  45. for c in cursor:
  46. custom_name = c['domain']
  47. if custom_name in d:
  48. if custom_name == 'hhh.com.tw' and c['num']==1:
  49. d['hhh.com.tw/designer']+=1
  50. d[custom_name]+=1
  51. idx += 1
  52. if idx <= 3:
  53. elmt = c['kw']
  54. domain = c['domain']
  55. custom_name = name[domain]
  56. result += "[" + str(c['ranking']) + "]:" + elmt + " "+ f"({custom_name})\n"
  57. per_total_click = f"毛怪:{d['beastparadise.net']}\n清原:{d['taroboba-yuan.com']}\n火柴星人:{d['match-planet.com']}\n幸福空間:{d['hhh.com.tw']}\n幸福空間設計師:{d['hhh.com.tw/designer']}\n仁本:{d['sctt.com.tw']}\n"
  58. print(per_total_click)
  59. msg_per_total_click = '\n點擊次數總計:\n' + per_total_click
  60. msg = "\n機器人執行次數:" + str(idx)
  61. <<<<<<< HEAD
  62. ga = main()['ga:sessions']
  63. ga_sessions = '\n幸福空間的GA Sessions'+ ga
  64. =======
  65. ga_sessions = '\n幸福空間的GA Sessions'+main()['ga:sessions']
  66. >>>>>>> 604b4f0737fe7f055de28e84a0a4697a346701cf
  67. send_msg(msg_per_total_click + result + ga_sessions)
  68. # schtasks /create /sc minute /mo 30 /sd 2022/05/050 /st 9:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"
  69. SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
  70. sys.path.append(os.path.dirname(SCRIPT_DIR))