Beispiel #1
0
def Send():
    user = config.USER
    password = config.PASSWORD
    to_addr = config.TO_ADDR
    from_addr = config.FROM_ADDR
    host = config.HOST

    sbj = "[BilibiliUP]"

    # 获取所有有更新的UP主,并添加到主题中
    cards = Dynamic.ListUpdate()
    # 没有更新时不发送
    if len(cards) == 0:
        if config.DEBUG == True:
            print("没有更新")
        return
    for card in cards:
        if sbj.find(card.uname) == -1:
            sbj = sbj + ' ' + card.uname

    # 构建发送内容与头部
    msg = MIMEText(__CreateHTML(cards), "html", "utf-8")
    msg['From'] = __format_addr("BilibiliUP<*****@*****.**>")
    msg['To'] = __format_addr("Anscor<*****@*****.**>")
    msg['Subject'] = Header(sbj, "utf-8").encode()

    # 发送
    server = smtplib.SMTP(host, 25)
    if config.DEBUG == True:
        server.set_debuglevel(True)
    server.login(user, password)
    server.sendmail(from_addr, [from_addr, to_addr], msg.as_string())
    server.quit()
Beispiel #2
0
            li = self.listItem
            li = li.replace('{ UPName }', key)

            vfs = ''
            for card in value:
                vfs = vfs + self.__RenderVideoInfo(card)
            li = li.replace('{ VideoInfo }', vfs)

            listItems = listItems + li

        result = result.replace('{ list-item }', listItems)

        return result

    def __RenderVideoInfo(self, card):
        vi = self.videoInfo

        vi = vi.replace('{ VideoLink }',
                        'https://www.bilibili.com/video/av' + str(card.av))
        vi = vi.replace('{ CoverImgSrc }', card.cover + '@160w_100h.webp')
        vi = vi.replace('{ VideoTitle }', card.title)
        vi = vi.replace('{ VideoDescription }',
                        card.desc.replace('\n', '<br />'))

        return vi


if __name__ == '__main__':
    cs = Dynamic.ListUpdate()
    pr = PageRenderer()
    print(pr.Render(cs))