Drkcore

14 11 2012 Python Tweet

ApressのEbooksDailyDealをGmailに送る

Nexus7を購入してから次の2つの電子書籍のDailyDealにはよく目を通すようになった。

  • O'Reilly Deal of the Day
  • Deal of the Day (Apress)

ApressのほうはGoogle Readerでうまく更新されなくてちょっと困ったので、毎朝Gmailに送るようにしてみた。

import requests
import feedparser
import smtplib
from email.MIMEText import MIMEText
from email.Header import Header
from email.Utils import formatdate

EMAIL = 'your_account@gmail.com'
PASSWORD = 'your_password'

def sendmail(subject, body):
    msg = MIMEText(body, 'plain', 'utf-8')
    msg['Subject'] = Header(subject, 'utf-8')
    msg['From'] = EMAIL
    msg['To'] = EMAIL
    msg['Date'] = formatdate()

    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login(EMAIL, PASSWORD)
    s.sendmail(EMAIL, EMAIL, msg.as_string())
    s.close()

if __name__ == '__main__':

    r = requests.get("http://www.apress.com/index.php/dailydeals/index/rss")

    if r.status_code == 200:
        d = feedparser.parse(r.content)
        e = d.entries[0]
        sendmail(
            u"[APRESS DailyDeal] {}".format(e.title),
            u"{}\n\n{}".format(e.summary, e.links[0].href)
            )

ちなみに本日のディールはProtect Your Wealth from the Ravages of Inflationという本で僕は想定読者ではなかった。

people who have reached a level of financial stability and whose income is greater than monthly expenses.

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021