make email parameters configurable
This commit is contained in:
parent
393caae381
commit
0c32563851
@ -4,3 +4,9 @@ user = atomstrom
|
|||||||
password = atomstrom
|
password = atomstrom
|
||||||
hostname = localhost
|
hostname = localhost
|
||||||
database = atomstrom
|
database = atomstrom
|
||||||
|
|
||||||
|
[email]
|
||||||
|
sender = dummy@dummy.invalid
|
||||||
|
receiver = dummy@dummy.invalid
|
||||||
|
prefix_single = [as]
|
||||||
|
prefix_digest = [atomstrom]
|
||||||
|
24
atomstrom.py
24
atomstrom.py
@ -146,9 +146,8 @@ def get_entry_text(entry):
|
|||||||
text = 'no text, sorry'
|
text = 'no text, sorry'
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def mail_daily_digest(session):
|
def mail_daily_digest(session, sender, receiver, prefix):
|
||||||
print 'mailing daily digest...'
|
print 'mailing daily digest...'
|
||||||
sender = 'atomstrom'
|
|
||||||
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.firstfetched)).all():
|
||||||
@ -159,22 +158,21 @@ def mail_daily_digest(session):
|
|||||||
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 = '[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)
|
send_mail(sender, subject, body)
|
||||||
|
|
||||||
def mail_single_entry(feed, feedinfo, entry):
|
def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
|
||||||
sender = feedinfo.title
|
subject = '%s %s' % (prefix, entry.title)
|
||||||
subject = '[atomstrom] %s' % entry.title
|
|
||||||
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, subject, body)
|
||||||
|
|
||||||
def mail_single_entries(session):
|
def mail_single_entries(session, sender, receiver, prefix):
|
||||||
print 'mailing 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():
|
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):
|
def fetch_readability(link):
|
||||||
text = hn.upgradeLink(link)
|
text = hn.upgradeLink(link)
|
||||||
@ -272,9 +270,15 @@ if __name__ == '__main__':
|
|||||||
if options.fetch:
|
if options.fetch:
|
||||||
fetch_all_feeds(session)
|
fetch_all_feeds(session)
|
||||||
if options.single:
|
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:
|
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):
|
if not (options.fetch or options.single or options.daily):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user