2013-03-26 20:20:51 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: utf-8
|
|
|
|
|
|
|
|
from sqlalchemy import Column, Integer, ForeignKey, String, Text, DateTime
|
|
|
|
from sqlalchemy.orm import relation, backref
|
|
|
|
from datetime import datetime
|
|
|
|
from time import mktime
|
2013-03-26 21:27:39 +01:00
|
|
|
import pprint
|
2013-03-26 20:20:51 +01:00
|
|
|
|
|
|
|
from models import Base
|
|
|
|
|
|
|
|
class Entry(Base):
|
|
|
|
__tablename__ = 'entry'
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
feed_id = Column(Integer, ForeignKey('feed.id'))
|
|
|
|
feed = relation("Feed", backref=backref('entry'))
|
|
|
|
title = Column(String(255))
|
|
|
|
link = Column(String(255))
|
|
|
|
summary = Column(Text)
|
|
|
|
content = Column(Text)
|
|
|
|
author = Column(String(255))
|
|
|
|
enclosures = Column(Text)
|
|
|
|
|
|
|
|
resolvedlink = Column(String(255))
|
|
|
|
fullpage = Column(Text)
|
|
|
|
readability = Column(Text)
|
|
|
|
updated = Column(DateTime)
|
|
|
|
firstfetched = Column(DateTime)
|
|
|
|
lastfetched = Column(DateTime)
|
|
|
|
sent = Column(DateTime)
|
|
|
|
|
|
|
|
def __init__(self, entry):
|
|
|
|
self.update(entry)
|
|
|
|
self.firstfetched = datetime.now()
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "<Entry('%s','%s','%s')>" % (self.title, "", "")
|
|
|
|
|
|
|
|
def update(self, entry):
|
|
|
|
if entry.has_key('title'):
|
|
|
|
self.title = entry.get('title')
|
|
|
|
if entry.has_key('link'):
|
|
|
|
self.link = entry.get('link')
|
|
|
|
if entry.has_key('summary'):
|
|
|
|
self.summary = entry.get('summary')
|
|
|
|
if entry.has_key('content'):
|
|
|
|
self.content = entry.get('content')[0].value
|
|
|
|
if entry.has_key('author'):
|
|
|
|
self.author = entry.get('author')
|
|
|
|
if entry.has_key('updated_parsed'):
|
|
|
|
updated_parsed = entry.get('updated_parsed')
|
|
|
|
self.updated = datetime.fromtimestamp(mktime(updated_parsed))
|
|
|
|
if entry.has_key('enclosures') and len(entry.get('enclosures')) > 0:
|
|
|
|
print 'enclosures';
|
|
|
|
pp=pprint.PrettyPrinter(depth=4)
|
|
|
|
pp.pprint(entry.get('enclosures'))
|
|
|
|
#self.enclosures = entry.get('enclosures')
|
|
|
|
self.lastfetched = datetime.now()
|
2013-04-03 00:06:06 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|