implemented mail sending

This commit is contained in:
Ronald Schaten 2013-03-19 23:03:33 +01:00
parent f6e57378f2
commit b78ed4ba02

View File

@ -161,19 +161,32 @@ def get_entry_text(entry):
def mail_daily_digest(session, sender, receiver, prefix):
print 'mailing daily digest...'
entries = 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).\
filter(Entry.sent == None).\
order_by(desc(Entry.firstfetched), Feedinfo.title, Entry.title).\
all()
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.updated)).all():
for feed, feedinfo, entry in entries:
count = count + 1
body = body + '=> %s - %s\n' % (entry.updated.strftime('%y%m%d-%H%M'), feedinfo.title)
body = body + '=> %s - %s\n' % (entry.firstfetched.strftime('%y%m%d-%H%M'), feedinfo.title)
body = body + ' %s\n' % entry.title
body = body + '%s\n' % get_entry_text(entry)[0:100]
body = body + '%s\n\n' % entry.link
today = datetime.now()
subject = '%s (%s) - %d entries' % (today.strftime('%y%m%d'), today.strftime('%A'), count)
if prefix != '':
subject = '%s %s' % (prefix, subject)
send_mail(sender, receiver, subject, body)
if count > 0:
today = datetime.now()
subject = '%s (%s) - %d entries' % (today.strftime('%y%m%d'), today.strftime('%A'), count)
if prefix != '':
subject = '%s %s' % (prefix, subject)
send_mail(sender, receiver, subject, body)
for feed, feedinfo, entry in entries:
entry.sent = datetime.now()
else:
print 'no unmailed digest-entries found... not sending mail.'
def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
subject = '%s' % (entry.title)
@ -183,11 +196,25 @@ def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
body = body + '%s\n' % feedinfo.link
body = body + '%s\n' % entry.link
send_mail(sender, receiver, subject, body)
entry.sent = datetime.now()
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():
count = 0
entries = 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).\
filter(Entry.sent == None).\
all()
for feed, feedinfo, entry in entries:
mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix)
count = count + 1
if count > 0:
print 'sent %d mails' % count
else:
print 'no unmailed single entries found... not sending mail.'
def fetch_readability(link):
text = hn.upgradeLink(link)