make email parameters configurable

This commit is contained in:
Ronald Schaten 2013-03-19 19:32:10 +01:00
parent 393caae381
commit 0c32563851
2 changed files with 20 additions and 10 deletions

View File

@ -4,3 +4,9 @@ user = atomstrom
password = atomstrom
hostname = localhost
database = atomstrom
[email]
sender = dummy@dummy.invalid
receiver = dummy@dummy.invalid
prefix_single = [as]
prefix_digest = [atomstrom]

View File

@ -146,9 +146,8 @@ def get_entry_text(entry):
text = 'no text, sorry'
return text
def mail_daily_digest(session):
def mail_daily_digest(session, sender, receiver, prefix):
print 'mailing daily digest...'
sender = 'atomstrom'
body = ''
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():
@ -159,22 +158,21 @@ def mail_daily_digest(session):
body = body + '\n'
body = body + 'link: [%s]\n\n' % entry.link
today = datetime.now()
subject = '[atomstrom] %s (%s) - %d entries' % (today.strftime('%y%m%d'), today.strftime('%A'), count)
subject = '%s %s (%s) - %d entries' % (prefix, today.strftime('%y%m%d'), today.strftime('%A'), count)
send_mail(sender, subject, body)
def mail_single_entry(feed, feedinfo, entry):
sender = feedinfo.title
subject = '[atomstrom] %s' % entry.title
def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
subject = '%s %s' % (prefix, entry.title)
body = get_entry_text(entry)
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(session):
def mail_single_entries(session, sender, receiver, prefix):
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)
mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix)
def fetch_readability(link):
text = hn.upgradeLink(link)
@ -272,9 +270,15 @@ if __name__ == '__main__':
if options.fetch:
fetch_all_feeds(session)
if options.single:
mail_single_entries(session)
sender = config.get('email', 'sender')
receiver = config.get('email', 'receiver')
prefix = config.get('email', 'prefix_single', 1)
mail_single_entries(session, sender, receiver, prefix)
if options.daily:
mail_daily_digest(session)
sender = config.get('email', 'sender')
receiver = config.get('email', 'receiver')
prefix = config.get('email', 'prefix_digest')
mail_daily_digest(session, sender, receiver, prefix)
if not (options.fetch or options.single or options.daily):
parser.print_help()