digest-mails: truncate body text, remove spare whitespace

This commit is contained in:
Ronald Schaten 2013-03-27 22:34:11 +01:00
parent 33da084705
commit ff245d4fd6

View File

@ -49,6 +49,13 @@ def get_entry_text(entry):
text = 'no text, sorry' text = 'no text, sorry'
return text return text
def truncate_text(content, length=100, suffix='...'):
content = " ".join(content.split())
if len(content) <= length:
return content
else:
return content[:length].rsplit(' ', 1)[0]+suffix
def mail_daily_digest(session, sender, receiver, prefix): def mail_daily_digest(session, sender, receiver, prefix):
print 'mailing daily digest...' print 'mailing daily digest...'
entries = session.query(Feed, Feedinfo, Entry).\ entries = session.query(Feed, Feedinfo, Entry).\
@ -69,7 +76,7 @@ def mail_daily_digest(session, sender, receiver, prefix):
try: try:
body = body + '=> %s - %s\n' % (entry.firstfetched.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' % entry.title
body = body + '%s\n' % get_entry_text(entry)[0:100] body = body + '%s\n' % truncate_text(get_entry_text(entry), 250)
body = body + '%s\n\n' % link body = body + '%s\n\n' % link
except: except:
print 'ERROR processing entry %s' % entry.id; print 'ERROR processing entry %s' % entry.id;