Esempio n. 1
0
def main():
    # 获取明天的农历日期(农历2018年七月初一)
    lu_date = LunarDate.tomorrow()
    tom_day = f"{fix_zero(lu_date.month)}{fix_zero(lu_date.day)}"
    # 查询数据
    b_sql = f"select modify_time,name,relation,lunar_birth from birth where lunar_birth='{tom_day}'"
    b_data = m_load_data(b_sql)
    if len(b_data) > 0:
        # 生成邮件
        msg_root = MIMEMultipart('related')
        msg_root['From'] = Header("Remind", 'utf-8')
        msg_root['To'] = "Y.G"
        subject = f'明日生日提醒-记得关注'
        msg_root['Subject'] = Header(subject, 'utf-8')
        msg_alternative = MIMEMultipart('alternative')
        b_info = ""
        for item in b_data:
            b_info += "<tr>"
            for var2 in range(0, 4):
                b_info += f"<td>{item[var2]}</td>"
            b_info += "</tr>"
        mail_msg = f"""
        {CSS_INFO}
        <h2>这些小可爱明天要过生日了,记得送祝福哦!!!</h2>
        <table class="pure-table pure-table-horizontal">
            <thead>
            <tr>
                <th>-_-</th>
                <th>Name</th>
                <th>relation</th>
                <th>birth</th>
            </tr>
            </thead>
            <tbody>
                {b_info}
            </tbody>
        </table>
        <br/>
        <hr size=1 color='gray' width='600' align='left'/>
        """
        msg_alternative.attach(MIMEText(mail_msg, 'html', 'utf-8'))
        msg_root.attach(msg_alternative)
        # 发送邮件
        send_email(msg_root)
    else:
        print("明天没有过生日的人")
Esempio n. 2
0
 def test_create_specific_dates(self):
     today = LunarDate.today()
     self.assertEqual(1, LCalendars.delta(LunarDate.tomorrow(), today))
     self.assertEqual(-1, LCalendars.delta(LunarDate.yesterday(), today))
     self.assertEqual(5, LCalendars.delta(today.after(5), today))
     self.assertEqual(-5, LCalendars.delta(today.before(5), today))