53 lines
1.8 KiB
Python
53 lines
1.8 KiB
Python
|
#!/usr/bin/env python
|
||
|
#coding: utf-8
|
||
|
|
||
|
from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
|
||
|
from sqlalchemy.orm import relation, backref
|
||
|
from datetime import datetime
|
||
|
|
||
|
from models import Base
|
||
|
|
||
|
class Feedinfo(Base):
|
||
|
__tablename__ = 'feedinfo'
|
||
|
|
||
|
id = Column(Integer, primary_key=True)
|
||
|
feed_id = Column(Integer, ForeignKey('feed.id'))
|
||
|
feed = relation("Feed", backref=backref('feedinfo', uselist=False))
|
||
|
title = Column(String(255))
|
||
|
link = Column(String(255))
|
||
|
subtitle = Column(String(255))
|
||
|
author = Column(String(255))
|
||
|
publisher = Column(String(255))
|
||
|
status = Column(Integer)
|
||
|
version = Column(String(16))
|
||
|
encoding = Column(String(16))
|
||
|
bozo = Column(Integer)
|
||
|
|
||
|
lastfetched = Column(DateTime)
|
||
|
lastsuccessful = Column(DateTime)
|
||
|
|
||
|
def __init__(self, parser):
|
||
|
self.update(parser)
|
||
|
|
||
|
def __repr__(self):
|
||
|
return "<Feedinfo('%s','%s','%s')>" % (self.title, self.subtitle, self.author)
|
||
|
|
||
|
def update(self, parser):
|
||
|
if parser.feed.has_key('title'):
|
||
|
self.title = parser.feed.get('title')
|
||
|
if parser.feed.has_key('link'):
|
||
|
self.link = parser.feed.get('link')
|
||
|
if parser.feed.has_key('subtitle'):
|
||
|
self.subtitle = parser.feed.get('subtitle')
|
||
|
if parser.feed.has_key('author'):
|
||
|
self.author = parser.feed.get('author')
|
||
|
if parser.feed.has_key('publisher'):
|
||
|
self.author = parser.feed.get('publisher')
|
||
|
self.status = parser.get('status')
|
||
|
self.version = parser.get('version')
|
||
|
self.encoding = parser.get('encoding')
|
||
|
self.bozo = parser.get('bozo')
|
||
|
self.lastfetched = datetime.now()
|
||
|
if parser.get('status') == 200 or parser.get('status') == 302:
|
||
|
self.lastsuccessful = datetime.now()
|