59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
#coding: utf-8
|
|
|
|
from sqlalchemy import Column, Integer, ForeignKey, String, DateTime
|
|
from datetime import datetime, timedelta
|
|
from random import randint
|
|
|
|
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)
|
|
nextfetch = 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()
|
|
if self.feed:
|
|
waitminutes = randint(int(self.feed.frequency * .75), int(self.feed.frequency * 1.25))
|
|
else:
|
|
waitminutes = 0
|
|
self.nextfetch = (datetime.now() + timedelta(minutes=waitminutes))
|
|
|