modified mail subject prefixes

This commit is contained in:
Ronald Schaten 2013-03-19 20:09:44 +01:00
parent dc5ba5c265
commit 193e47d2bb

View File

@ -12,6 +12,7 @@ import urllib
import hn import hn
import html2text import html2text
import ConfigParser import ConfigParser
import smtplib
from optparse import OptionParser from optparse import OptionParser
Base = declarative_base() Base = declarative_base()
@ -130,10 +131,8 @@ class Entry(Base):
self.lastfetched = datetime.now() self.lastfetched = datetime.now()
def send_mail(sender, subject, body): def send_mail(sender, receiver, subject, body):
print 'Sender: %s' % sender.decode('latin-1') print 'sending to %s: %s' % (receiver.decode('latin-1'), subject.decode('latin-1'))
print 'Subject: %s' % subject.decode('latin-1')
print 'Body: %s' % body.decode('latin-1')
def get_entry_text(entry): def get_entry_text(entry):
if entry.readability: if entry.readability:
@ -150,24 +149,28 @@ def mail_daily_digest(session, sender, receiver, prefix):
print 'mailing daily digest...' print 'mailing daily digest...'
body = '' body = ''
count = 0 count = 0
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==1).order_by(desc(Entry.firstfetched)).all(): 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==1).order_by(desc(Entry.updated)).all():
count = count + 1 count = count + 1
body = body + '=> %s - %s\n' % (entry.firstfetched.strftime('%y%m%d-%H%M'), feedinfo.title) body = body + '=> %s - %s\n' % (entry.updated.strftime('%y%m%d-%H%M'), feedinfo.title)
body = body + ' %s\n' % entry.title body = body + ' %s\n' % entry.title
body = body + get_entry_text(entry)[0:100] body = body + get_entry_text(entry)[0:100]
body = body + '\n' body = body + '\n'
body = body + 'link: [%s]\n\n' % entry.link body = body + 'link: [%s]\n\n' % entry.link
today = datetime.now() today = datetime.now()
subject = '%s %s (%s) - %d entries' % (prefix, today.strftime('%y%m%d'), today.strftime('%A'), count) subject = '%s (%s) - %d entries' % (today.strftime('%y%m%d'), today.strftime('%A'), count)
send_mail(sender, subject, body) if prefix != '':
subject = '%s %s' % (prefix, subject)
send_mail(sender, receiver, subject, body)
def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix): def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
subject = '%s %s' % (prefix, entry.title) subject = '%s' % (entry.title)
if prefix != '':
subject = '%s %s' % (prefix, subject)
body = get_entry_text(entry) body = get_entry_text(entry)
body = body + '\n\n' body = body + '\n\n'
body = body + 'site: [%s]\n' % feedinfo.link body = body + 'site: [%s]\n' % feedinfo.link
body = body + 'link: [%s]\n' % entry.link body = body + 'link: [%s]\n' % entry.link
send_mail(sender, subject, body) send_mail(sender, receiver, subject, body)
def mail_single_entries(session, sender, receiver, prefix): def mail_single_entries(session, sender, receiver, prefix):
print 'mailing single entries...' print 'mailing single entries...'
@ -272,7 +275,7 @@ if __name__ == '__main__':
if options.single: if options.single:
sender = config.get('email', 'sender') sender = config.get('email', 'sender')
receiver = config.get('email', 'receiver') receiver = config.get('email', 'receiver')
prefix = config.get('email', 'prefix_single', 1) prefix = config.get('email', 'prefix_single')
mail_single_entries(session, sender, receiver, prefix) mail_single_entries(session, sender, receiver, prefix)
if options.daily: if options.daily:
sender = config.get('email', 'sender') sender = config.get('email', 'sender')