2013-03-26 20:20:51 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding: utf-8
|
|
|
|
|
|
|
|
from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
|
|
|
|
from sqlalchemy.orm import relation, backref
|
2013-03-28 23:35:20 +01:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from random import randint
|
2013-03-26 20:20:51 +01:00
|
|
|
|
|
|
|
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)
|
2013-03-28 23:35:20 +01:00
|
|
|
nextfetch = Column(DateTime)
|
2013-03-26 20:20:51 +01:00
|
|
|
|
|
|
|
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()
|
2013-03-28 23:35:20 +01:00
|
|
|
waitminutes = randint(int(self.feed.frequency * .75), int(self.feed.frequency * 1.25))
|
|
|
|
self.nextfetch = (datetime.now() + timedelta(minutes=waitminutes))
|
|
|
|
|