2013-03-26 20:20:51 +01:00
|
|
|
from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
|
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'))
|
|
|
|
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-04-04 22:36:48 +02:00
|
|
|
if self.feed:
|
|
|
|
waitminutes = randint(int(self.feed.frequency * .75), int(self.feed.frequency * 1.25))
|
|
|
|
else:
|
|
|
|
waitminutes = 0
|
2013-03-28 23:35:20 +01:00
|
|
|
self.nextfetch = (datetime.now() + timedelta(minutes=waitminutes))
|
|
|
|
|
2013-04-09 23:39:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|