# Path: fooltrader/settings.py
# SMTP_HOST = 'smtpdm.aliyun.com'
# 
# SMTP_PORT = '80'
# 
# EMAIL_PASSWORD = ''
# 
# EMAIL_USER_NAME = ''
# 
# WEIXIN_APP_ID = ""
# 
# WEIXIN_APP_SECRECT = ""


import email
import json
import logging
import smtplib
import requests
import schedule
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from fooltrader.settings import SMTP_HOST, SMTP_PORT, EMAIL_PASSWORD, EMAIL_USER_NAME, WEIXIN_APP_ID, WEIXIN_APP_SECRECT
        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('fooltrader').encode(), EMAIL_USER_NAME)
        msg['To'] = to_user

        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:
            smtp_client.sendmail(EMAIL_USER_NAME, to_user, msg.as_string())
        except Exception as e:
            self.logger.exception('send email failed', e)


class WeixinAction(Action):
    GET_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}".format(
        WEIXIN_APP_ID, WEIXIN_APP_SECRECT)

    GET_TEMPLATE_URL = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={}"
    SEND_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={}"

    token = None

    def __init__(self) -> None:
        self.refresh_token()
        schedule.every(10).minutes.do(self.refresh_token)

    def refresh_token(self):

# Path: fooltrader/settings.py
# SMTP_HOST = 'smtpdm.aliyun.com'
# 
# SMTP_PORT = '80'
# 
# EMAIL_PASSWORD = ''
# 
# EMAIL_USER_NAME = ''
# 
# WEIXIN_APP_ID = ""
# 
# WEIXIN_APP_SECRECT = ""


# Path: fooltrader/bot/action/msg_action.py
import email
import json
import logging
import smtplib
import requests
import schedule
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from fooltrader.settings import SMTP_HOST, SMTP_PORT, EMAIL_PASSWORD, EMAIL_USER_NAME, WEIXIN_APP_ID, WEIXIN_APP_SECRECT

        msg['Subject'] = Header(title).encode()
        msg['From'] = "{} <{}>".format(Header('fooltrader').encode(), EMAIL_USER_NAME)
        msg['To'] = to_user

        msg['Message-id'] = email.utils.make_msgid()
        msg['Date'] = email.utils.formatdate()

        plain_text = MIMEText(body, _subtype='plain', _charset='UTF-8')
        msg.attach(plain_text)

        try:
            smtp_client.sendmail(EMAIL_USER_NAME, to_user, msg.as_string())
        except Exception as e:
            self.logger.exception('send email failed', e)


class WeixinAction(Action):
    GET_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}".format(
        WEIXIN_APP_ID, WEIXIN_APP_SECRECT)

    GET_TEMPLATE_URL = "https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token={}"
    SEND_MSG_URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={}"

    token = None

    def __init__(self) -> None:
        self.refresh_token()
        schedule.every(10).minutes.do(self.refresh_token)

    def refresh_token(self):

        resp = requests.get(self.GET_TOKEN_URL)