From 6529fdbdd80c6c4899c53478a5f6c830c92abd4d Mon Sep 17 00:00:00 2001 From: pictuga Date: Mon, 26 Jun 2023 01:30:47 +0200 Subject: [PATCH] Clean up sqlite code --- README.md | 11 +++++------ morss/caching.py | 15 +-------------- morss/morss.py | 2 +- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8e0f613..e2ce280 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ From git pip install git+https://git.pictuga.com/pictuga/morss.git#egg=morss[full] ``` -The full install includes all the cache backends. Otherwise, only in-memory and -sqlite3 caches are available. The full install also includes gunicorn (for more -efficient HTTP handling). +The full install includes all the cache backends. Otherwise, only in-memory +cache is available. The full install also includes gunicorn (for more efficient +HTTP handling). The dependency `lxml` is fairly long to install (especially on Raspberry Pi, as C code needs to be compiled). If possible on your distribution, try installing @@ -353,7 +353,7 @@ Using cache and passing arguments: ```python >>> import morss >>> url = 'http://feeds.bbci.co.uk/news/rss.xml' ->>> cache = '/tmp/morss-cache.db' # sqlite cache location +>>> cache = '/tmp/morss-cache' # diskcache cache location >>> options = {'csv':True} >>> xml_string = morss.process(url, cache, options) >>> xml_string[:50] @@ -367,11 +367,10 @@ under the hood. Doing it step-by-step: ```python -import morss, morss.crawler +import morss url = 'http://newspaper.example/feed.xml' options = morss.Options(csv=True) # arguments -morss.crawler.sqlite_default = '/tmp/morss-cache.db' # sqlite cache location url, rss = morss.FeedFetch(url, options) # this only grabs the RSS feed rss = morss.FeedGather(rss, url, options) # this fills the feed and cleans it up diff --git a/morss/caching.py b/morss/caching.py index b3950ef..837b235 100644 --- a/morss/caching.py +++ b/morss/caching.py @@ -104,20 +104,7 @@ class DiskCacheHandler(BaseCache): if 'CACHE' in os.environ: - if os.environ['CACHE'] == 'mysql': - default_cache = MySQLCacheHandler( - user = os.getenv('MYSQL_USER'), - password = os.getenv('MYSQL_PWD'), - database = os.getenv('MYSQL_DB'), - host = os.getenv('MYSQL_HOST', 'localhost') - ) - - elif os.environ['CACHE'] == 'sqlite': - default_cache = SQLiteCache( - os.getenv('SQLITE_PATH', ':memory:') - ) - - elif os.environ['CACHE'] == 'redis': + if os.environ['CACHE'] == 'redis': default_cache = RedisCacheHandler( host = os.getenv('REDIS_HOST', 'localhost'), port = int(os.getenv('REDIS_PORT', 6379)), diff --git a/morss/morss.py b/morss/morss.py index 7a080a1..b5836e2 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -428,7 +428,7 @@ def process(url, cache=None, options=None): options = Options(options) if cache: - caching.default_cache = caching.SQLiteCache(cache) + caching.default_cache = caching.DiskCacheHandler(cache) url, rss = FeedFetch(url, options) rss = FeedGather(rss, url, options)