2014-07-15 01:53:32 -04:00
|
|
|
from __future__ import with_statement
|
|
|
|
|
2014-06-29 06:05:33 -04:00
|
|
|
import os
|
|
|
|
import urllib
|
2014-12-02 14:09:53 -05:00
|
|
|
|
2014-06-29 06:05:33 -04:00
|
|
|
import sickbeard
|
|
|
|
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard import encodingKludge as ek
|
2014-07-15 01:53:32 -04:00
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
|
2014-12-03 07:10:00 -05:00
|
|
|
from feedcache.cache import Cache
|
2014-12-24 10:48:36 -05:00
|
|
|
|
2014-12-02 14:09:53 -05:00
|
|
|
from sqliteshelf import SQLiteShelf
|
2014-06-29 06:05:33 -04:00
|
|
|
|
2014-12-11 13:06:50 -05:00
|
|
|
|
2014-06-29 06:05:33 -04:00
|
|
|
class RSSFeeds:
|
2014-12-24 10:48:36 -05:00
|
|
|
def __init__(self, db_name='feeds'):
|
2014-12-02 14:09:53 -05:00
|
|
|
try:
|
2014-12-03 07:10:00 -05:00
|
|
|
db_name = ek.ek(os.path.join, sickbeard.CACHE_DIR, 'rss', db_name) + '.db'
|
|
|
|
if not os.path.exists(os.path.dirname(db_name)):
|
|
|
|
sickbeard.helpers.makeDir(os.path.dirname(db_name))
|
|
|
|
|
2014-12-02 14:09:53 -05:00
|
|
|
self.rssDB = SQLiteShelf(db_name)
|
|
|
|
except Exception as e:
|
2014-12-24 10:48:36 -05:00
|
|
|
logger.log(u"FeedParser error: " + ex(e), logger.DEBUG)
|
2014-06-29 06:05:33 -04:00
|
|
|
|
|
|
|
def clearCache(self, age=None):
|
2014-07-15 01:53:32 -04:00
|
|
|
try:
|
2014-12-24 10:48:36 -05:00
|
|
|
Cache(self.rssDB).purge(age)
|
2014-12-03 07:10:00 -05:00
|
|
|
finally:
|
|
|
|
self.rssDB.close()
|
2014-06-29 06:05:33 -04:00
|
|
|
|
2014-12-24 10:48:36 -05:00
|
|
|
def getFeed(self, url, post_data=None, request_headers=None, items=None):
|
|
|
|
|
2014-07-14 22:00:53 -04:00
|
|
|
|
|
|
|
if post_data:
|
|
|
|
url += urllib.urlencode(post_data)
|
|
|
|
|
2014-07-15 01:53:32 -04:00
|
|
|
try:
|
2014-12-24 10:48:36 -05:00
|
|
|
resp = Cache(self.rssDB).fetch(url, force_update=True, request_headers=request_headers)
|
2014-12-03 07:10:00 -05:00
|
|
|
finally:
|
2014-12-08 04:41:42 -05:00
|
|
|
self.rssDB.close()
|
|
|
|
|
2014-12-24 10:48:36 -05:00
|
|
|
return resp
|