2013-03-26 20:20:51 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: utf-8
|
|
|
|
|
2013-04-03 00:06:06 +02:00
|
|
|
from sqlalchemy import Column, Integer, String, Boolean, Enum
|
2013-04-07 13:34:36 +02:00
|
|
|
from sqlalchemy.orm import relationship, backref
|
2013-03-26 20:20:51 +01:00
|
|
|
|
|
|
|
from models import Base
|
|
|
|
|
2013-04-07 13:34:36 +02:00
|
|
|
|
2013-03-26 20:20:51 +01:00
|
|
|
class Feed(Base):
|
|
|
|
__tablename__ = 'feed'
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
url = Column(String(255))
|
|
|
|
frequency = Column(Integer)
|
|
|
|
daily = Column(Boolean)
|
|
|
|
resolveredirects = Column(Boolean)
|
|
|
|
readability = Column(Boolean)
|
|
|
|
fullpage = Column(Boolean)
|
2013-04-03 00:06:06 +02:00
|
|
|
contentcolumn = Column(Enum('summary', 'content', 'fullpage', 'readability'))
|
|
|
|
html2textcontent = Column(Boolean)
|
2013-03-26 20:20:51 +01:00
|
|
|
html2textignoreimages = Column(Boolean)
|
|
|
|
enabled = Column(Boolean)
|
2013-04-07 13:34:36 +02:00
|
|
|
entries = relationship("Entry", backref=backref('feed'), cascade='all, delete, delete-orphan')
|
|
|
|
feedinfo = relationship("Feedinfo", backref=backref('feed'), cascade='all, delete, delete-orphan', uselist=False)
|
2013-03-26 20:20:51 +01:00
|
|
|
|
2013-04-03 00:06:06 +02:00
|
|
|
def __init__(self, url, daily, readability, fullpage, enabled, html2textcontent):
|
2013-03-26 20:20:51 +01:00
|
|
|
self.url = url
|
|
|
|
self.daily = daily
|
|
|
|
self.readability = readability
|
|
|
|
self.fullpage = fullpage
|
2013-04-03 00:06:06 +02:00
|
|
|
self.html2textcontent = html2textcontent
|
2013-03-26 20:20:51 +01:00
|
|
|
self.enabled = enabled
|
|
|
|
|
2013-04-04 20:40:19 +02:00
|
|
|
def __unicode__(self):
|
|
|
|
id = self.id
|
|
|
|
if self.feedinfo:
|
|
|
|
title = self.feedinfo.title
|
|
|
|
last = self.feedinfo.lastsuccessful
|
|
|
|
else:
|
|
|
|
title = '<unknown>'
|
|
|
|
last = '<never>'
|
2013-04-07 13:43:34 +02:00
|
|
|
if self.enabled:
|
|
|
|
enabled = 'enabled'
|
|
|
|
else:
|
|
|
|
enabled = 'DISABLED'
|
2013-04-07 13:34:36 +02:00
|
|
|
entries = len(self.entries)
|
2013-04-04 20:40:19 +02:00
|
|
|
url = self.url
|
2013-04-07 13:43:34 +02:00
|
|
|
return u'%3d %s (%d entries, last fetched %s, %s)\n %s' % (id, title, entries, last, enabled, url)
|
2013-04-04 20:40:19 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return unicode(self).encode('utf-8')
|
|
|
|
|
2013-03-26 20:20:51 +01:00
|
|
|
def __repr__(self):
|
2013-04-04 20:40:19 +02:00
|
|
|
return "<Feed('%d','%s')>" % (self.id, self.url)
|
2013-04-07 13:34:36 +02:00
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
self.entries[:] = []
|
|
|
|
self.feedinfo = None
|