Esempio n. 1
0
def test_send_email():
    """
    测试发送email的功能
    :return:
    """
    conf = setting.Configuration("email.yaml").conf
    send_email = SendEmail()
    with open("../conf/email-template.html", "r",
              encoding="utf-8") as f:  # 打开文件
        data = f.read()  # 读取文件
    mail_content = """\
               <tr align="center">
                    <td>
                        <a href="https://cn.tradingview.com/chart/?symbol=SSE:000027">SZSE:000027</a>
                    </td>
                    <td>
                        深圳能源
                    </td>
                    <td>
                        29.000
                    </td>
                </tr>
               """
    mail_content = data.replace("$content", mail_content)
    send_email.send(tomail=[x["email"] for x in conf["toEmails"]],
                    subject='行情计算日报',
                    content=mail_content)
Esempio n. 2
0
 def __init__(self):
     """
     初始化
     """
     self.conf = setting.Configuration("email.yaml").conf
     '''用户信息'''
     self.from_addr = self.conf["from"]["email"]
     '''腾讯QQ邮箱或腾讯企业邮箱必须使用授权码进行第三方登陆'''
     self.password = self.conf["from"]["password"]
     '''腾讯服务器地址smtp.exmail.qq.com'''
     self.smtp_server = self.conf["from"]["server"]
     self.server = smtplib.SMTP_SSL(self.smtp_server,
                                    self.conf["from"]["port"])
     self.msg = MIMEText('test', "html", 'utf-8')
Esempio n. 3
0
    def handle_report(self, results, is_send=True):
        """
        发送报告
        :param is_send 是否发送
        :param results: 计算结果集dataframe
        :return:
        """
        flog.FinanceLoger.logger.info("处理策略执行结果,发送报告...")
        conf = setting.Configuration("email.yaml").conf
        hodl_list = []
        db_session = self.base_data.get_session()
        holds = db_session.query(Setting).filter(
            Setting.name == 'holds').first()
        if holds is not None:
            hodl_list = json.loads(holds.value)
        send_email = mil.SendEmail()
        now = datetime.datetime.now()
        prompts = {
            bdata.SecurityStatus.Strong: "可能由弱变强",
            bdata.SecurityStatus.Weakness: "可能由强变弱"
        }

        if not is_send:
            for k in results:
                for m in k:
                    results[m].to_csv("{0:%Y%m%d%H%M%S-}-{1}.csv".format(
                        now, m.name))
            return
        with open(conf["template"], "r", encoding="utf-8") as f:  # 打开文件
            data = f.read()  # 读取文件
        content = ""
        # securities.to_csv("sss4.csv")
        title = '''
         <div style="line-height: 200%;">
                <span
                    style="font-size: 14px; font-family: Helvetica, Arial, sans-serif; color: black;
                    line-height: 200%;">
                    <strong>订阅者您好: 本次报告基于{0:%Y-%m-%d}最近的交易日标的收盘价,交易额,市直,流通市值等计算生成</strong></span>
                </div>
        '''.format(now)
        m_content = ""
        for k in results:
            for m in results[k]:
                i = 0
                for index, row in results[k][m].iterrows():
                    code = row["security"]
                    style = ''
                    if code in hodl_list:
                        style = 'style="background-color: #ff00003b;"'
                    else:
                        style = 'style="background-color: none;"'
                    tradingview_code = ts.jqcode_to_trading(code)
                    easymoney_code = ts.jqcode_to_eastmoney(
                        code, k == bdata.SecurityType.Index)
                    industry = ""
                    if k is bdata.SecurityType.Stock:
                        industry = ",".join(
                            self.base_data.get_industry_by_security(code))
                        if '非银金融I' in industry or '房地产I' in industry:
                            continue
                    i += 1
                    content += """\
                                   <tr align="center" {7}>
                                        <td>{5}</td>
                                        <td>
                                            <a href="https://cn.tradingview.com/chart/?symbol={0}">{0}</a>
                                        </td>
                                        <td>
                                            <a href="http://quote.eastmoney.com/{6}.html">{1}</a>
                                        </td>
                                        <td>
                                            {2}
                                        </td>
                                        <td>{3}</td>
                                        <td>{4}</td>
                                    </tr>
                                           """.format(tradingview_code,
                                                      row["display_name"],
                                                      industry, row["close"],
                                                      row["rel20"], i,
                                                      easymoney_code, style)

                str_table = """
                    <div style="line-height: 200%;">
                    <span
                        style="font-size: 14px; font-family: Helvetica, Arial, sans-serif; color: black; line-height: 200%;">
                        <strong>{0}-{1}列表</strong></span>
                    </div>
                    <table
                        border="1"
                        cellpadding="0"
                        cellspacing="0"
                        width="100%"
                        class="bmeContainerRow"
                        style="font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: black; 
                        line-height: 200%; border-collapse:collapse">
                        <tr align="center">
                            <th>序号</th>
                            <th>代码</th>
                            <th>名称</th>
                            <th>行业</th>
                            <th>收盘价</th>
                            <th>相对强度</th>
                        </tr>
                       {2}
                    </table>
                """.format(k.name, prompts[m], content)
                content = ""
                m_content += str_table

        mail_content = data.replace("$content", title + m_content)
        send_email.send(tomail=[x["email"] for x in conf["toEmails"]],
                        subject='行情计算日报',
                        content=mail_content)
        db_session.close()
Esempio n. 4
0
 def __init__(self, file_name):
     """
     初始化
     """
     self.config = st.Configuration(file_name)
Esempio n. 5
0
 def __init__(self):
     """
     初始化
     """
     self.log_status = False
     self.conf = setting.Configuration("data_provide.yaml").conf