implemented mail_single_entry()

This commit is contained in:
Ronald Schaten 2010-10-30 11:16:37 +02:00
parent e4fb328d48
commit 0b366a9d55

View File

@ -127,6 +127,35 @@ session = Session()
#session.add(Feed('http://www.heise.de/newsticker/heise-atom.xml', 1, 0, 0, 1)) #session.add(Feed('http://www.heise.de/newsticker/heise-atom.xml', 1, 0, 0, 1))
#session.add(Feed('http://blog.schatenseite.de/feed/', 1, 0, 0, 1)) #session.add(Feed('http://blog.schatenseite.de/feed/', 1, 0, 0, 1))
def send_mail(sender, subject, body):
print 'Sender: %s' % sender.decode('latin-1')
print 'Subject: %s' % subject.decode('latin-1')
print 'Body: %s' % body.decode('latin-1')
def mail_daily_digest():
pass
def mail_single_entry(feed, feedinfo, entry):
sender = feedinfo.title
subject = entry.title
if entry.readability:
body = entry.readability
elif entry.fullpage:
body = entry.fullpage
elif entry.summary:
body = entry.summary
else:
body = 'no text, sorry'
body = body + '\n\n'
body = body + 'site: [%s]\n' % feedinfo.link
body = body + 'link: [%s]\n' % entry.link
send_mail(sender, subject, body)
def mail_single_entries():
print "mailing single entries..."
for feed, feedinfo, entry in session.query(Feed, Feedinfo, Entry).filter(Feed.id==Feedinfo.feed_id).filter(Feed.id==Entry.feed_id).filter(Feed.enabled==1).filter(Feed.daily==0).all():
mail_single_entry(feed, feedinfo, entry)
def fetch_readability(link): def fetch_readability(link):
text = hn.upgradeLink(link) text = hn.upgradeLink(link)
text = text.decode('utf8') text = text.decode('utf8')
@ -145,9 +174,9 @@ def process_feed_entry(feed, entry):
return "-" return "-"
except Exception, e: except Exception, e:
thisentry = Entry(entry) thisentry = Entry(entry)
if feed.fullpage == 1: if feed.fullpage:
thisentry.fullpage = fetch_full_page(entry.link) thisentry.fullpage = fetch_full_page(entry.link)
if feed.readability == 1: if feed.readability:
thisentry.readability = fetch_readability(entry.link) thisentry.readability = fetch_readability(entry.link)
feed.entry.append(thisentry) feed.entry.append(thisentry)
return "+" return "+"
@ -181,7 +210,7 @@ def fetch_all_feeds():
print print
if __name__ == "__main__": if __name__ == "__main__":
print "main"
fetch_all_feeds() fetch_all_feeds()
mail_single_entries()
session.commit() session.commit()