Atomstrom/models/feed.py

60 lines
1.9 KiB
Python

#!/usr/bin/env python
#coding: utf-8
from sqlalchemy import Column, Integer, String, Boolean, Enum
from sqlalchemy.orm import relationship, backref
from models import Base
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)
contentcolumn = Column(Enum('summary', 'content', 'fullpage', 'readability'))
html2textcontent = Column(Boolean)
html2textignoreimages = Column(Boolean)
enabled = Column(Boolean)
entries = relationship("Entry", backref=backref('feed'), cascade='all, delete, delete-orphan')
feedinfo = relationship("Feedinfo", backref=backref('feed'), cascade='all, delete, delete-orphan', uselist=False)
def __init__(self, url, daily, readability, fullpage, enabled, html2textcontent):
self.url = url
self.daily = daily
self.readability = readability
self.fullpage = fullpage
self.html2textcontent = html2textcontent
self.enabled = enabled
def __unicode__(self):
id = self.id
if self.feedinfo:
title = self.feedinfo.title
last = self.feedinfo.lastsuccessful
else:
title = '<unknown>'
last = '<never>'
if self.enabled:
enabled = 'enabled'
else:
enabled = 'DISABLED'
entries = len(self.entries)
url = self.url
return u'%3d %s (%d entries, last fetched %s, %s)\n %s' % (id, title, entries, last, enabled, url)
def __str__(self):
return unicode(self).encode('utf-8')
def __repr__(self):
return "<Feed('%d','%s')>" % (self.id, self.url)
def reset(self):
self.entries[:] = []
self.feedinfo = None