minor change in db-structure, made mailtext column selectable

This commit is contained in:
Ronald Schaten 2013-04-03 00:06:06 +02:00
parent d1d127744c
commit d60783b6aa
3 changed files with 28 additions and 19 deletions

View File

@ -38,17 +38,6 @@ def send_mail(sender, receiver, subject, body):
s = smtplib.SMTP('localhost')
s.sendmail("", receiver[1], str_io.getvalue())
def get_entry_text(entry):
if entry.readability:
text = entry.readability
elif entry.fullpage:
text = entry.fullpage
elif entry.summary:
text = entry.summary
else:
text = 'no text, sorry'
return text
def truncate_text(content, length=100, suffix='...'):
content = " ".join(content.split())
if len(content) <= length:
@ -76,7 +65,7 @@ def mail_daily_digest(session, sender, receiver, prefix):
try:
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' % truncate_text(get_entry_text(entry), 250)
body = body + '%s\n' % truncate_text(entry.get_text(), 250)
body = body + '%s\n\n' % link
except:
print 'ERROR processing entry %s' % entry.id;
@ -101,7 +90,7 @@ def mail_single_entry(feed, feedinfo, entry, sender, receiver, prefix):
link = entry.link
if entry.resolvedlink:
link = entry.resolvedlink
body = '%s\n\n' % get_entry_text(entry)
body = '%s\n\n' % entry.get_text()
body = body + '%s\n' % feedinfo.link
body = body + '%s\n' % link
sender[0] = feedinfo.title
@ -165,13 +154,20 @@ def process_feed_entry(session, feed, entry):
if feed.readability:
print ' fetching readability <%s>' % entry.link
thisentry.readability = fetch_readability(entry.link)
if feed.html2textsummary:
if feed.html2textcontent:
print ' converting summary'
h2t = html2text.HTML2Text()
h2t.body_width = 0
if feed.html2textignoreimages:
h2t.ignore_images = True
thisentry.summary = h2t.handle(thisentry.summary)
if feed.contentcolumn == 'summary':
thisentry.summary = h2t.handle(thisentry.summary)
elif feed.contentcolumn == 'content':
thisentry.content = h2t.handle(thisentry.content)
elif feed.contentcolumn == 'fullpage':
thisentry.fullpage = h2t.handle(thisentry.fullpage)
elif feed.contentcolumn == 'readability':
thisentry.readability = h2t.handle(thisentry.readability)
feed.entry.append(thisentry)
session.commit()
return 1

View File

@ -57,3 +57,15 @@ class Entry(Base):
pp.pprint(entry.get('enclosures'))
#self.enclosures = entry.get('enclosures')
self.lastfetched = datetime.now()
def get_text(self):
if self.feed.contentcolumn == 'summary':
text = self.summary
elif self.feed.contentcolumn == 'content':
text = self.content
elif self.feed.contentcolumn == 'fullpage':
text = self.fullpage
elif self.feed.contentcolumn == 'readability':
text = self.readability
return text

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
#coding: utf-8
from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy import Column, Integer, String, Boolean, Enum
from models import Base
@ -15,16 +15,17 @@ class Feed(Base):
resolveredirects = Column(Boolean)
readability = Column(Boolean)
fullpage = Column(Boolean)
html2textsummary = Column(Boolean)
contentcolumn = Column(Enum('summary', 'content', 'fullpage', 'readability'))
html2textcontent = Column(Boolean)
html2textignoreimages = Column(Boolean)
enabled = Column(Boolean)
def __init__(self, url, daily, readability, fullpage, enabled, html2textsummary):
def __init__(self, url, daily, readability, fullpage, enabled, html2textcontent):
self.url = url
self.daily = daily
self.readability = readability
self.fullpage = fullpage
self.html2textsummary = html2textsummary
self.html2textcontent = html2textcontent
self.enabled = enabled
def __repr__(self):