import redis
import time
import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time
import os
import urllib.parse
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import codecs
import random
from bs4 import BeautifulSoup
import requests
import dataset
import time
import rpyc
import sys
import docker
import pymysql
pymysql.install_as_MySQLdb()
from monitor import GA_innnews

headers = {
        "Authorization": "Bearer " + "zsaS4I79fkbun9LLF8mQmeHL4PlEtBtN7OLzTp8m72Y",
        "Content-Type": "application/x-www-form-urlencoded"
}



def send_msg(kw):
    send_message = GA_innnews.main()
    params = {"message": kw+send_message['message']}
    print('通知結果',params)
    # r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)


db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/seo?charset=utf8mb4')
cursor=db.query('SELECT * FROM seo.nda_log where domain = "innews.com.tw" and datediff(now(),dt)=0 order by dt desc')
result="\n"
idx=0
for c in cursor:
    idx+=1
    if idx<=3:
        elmt=c['kw']
        result+="["+str(c['ranking'])+"]:"+elmt+"\n"

msg="\n機器人執行次數:"+str(idx)
send_msg(msg+result)
time.sleep(1800)

# schtasks /create /sc minute /mo 30 /sd 2022/05/050 /st 9:00 /et 23:00 /tn "linebat" /tr "C:\tmp\inn_line.bat"