1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-08-13 16:53:54 -04:00
SickRage/sickbeard/rssfeeds.py
echel0n e6389e47b1 Improved RSS feedparser/feedcache code for better performance and reliability.
Removed Shove module and depends.

Logging now automatically omits sensitive data such as usernames, passwords, and api keys and replaces them with asterisks in both log file and console.

Fixed versionChecker module to confirm it created a updater class before attempting to execute functions to avoid NoneType errors.
2014-12-02 11:09:53 -08:00

62 lines
2.0 KiB
Python

from __future__ import with_statement
import os
import urllib
import urlparse
import re
import sickbeard
from sickbeard import logger
from sickbeard import encodingKludge as ek
from sickbeard.exceptions import ex
from contextlib import closing
from lib.feedcache import cache
from sqliteshelf import SQLiteShelf
class RSSFeeds:
def __init__(self, db_name):
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))
try:
self.rssDB = SQLiteShelf(db_name)
except Exception as e:
logger.log(u"RSS error: " + ex(e), logger.DEBUG)
def clearCache(self, age=None):
try:
with closing(self.rssDB) as fs:
fc = cache.Cache(fs)
fc.purge(age)
except Exception as e:
logger.log(u"RSS error clearing cache: " + ex(e), logger.DEBUG)
def getFeed(self, url, post_data=None, request_headers=None):
parsed = list(urlparse.urlparse(url))
parsed[2] = re.sub("/{2,}", "/", parsed[2]) # replace two or more / with one
if post_data:
url += urllib.urlencode(post_data)
try:
with closing(self.rssDB) as fs:
fc = cache.Cache(fs)
feed = fc.fetch(url, False, False, request_headers)
if feed:
if 'entries' in feed:
return feed
elif 'error' in feed.feed:
err_code = feed.feed['error']['code']
err_desc = feed.feed['error']['description']
logger.log(
u"RSS ERROR:[%s] CODE:[%s]" % (err_desc, err_code), logger.DEBUG)
else:
logger.log(u"RSS error loading url: " + url, logger.DEBUG)
except Exception as e:
logger.log(u"RSS error: " + ex(e), logger.DEBUG)