From 4691f727928d300bec82fb7f8fc82fb63045f2fa Mon Sep 17 00:00:00 2001 From: The Dod Date: Sat, 17 Jan 2015 19:49:10 +0700 Subject: [PATCH] Fix bug when use_shortener is "False", document ur1.ca etc. --- README.md | 2 +- feed2twister.conf.example | 8 +++++++- feed2twister.py | 15 +++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c22d281..92c4e9f 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ edit it so that it contains similar settings to those you had at `conf.py` * [Twister](http://twister.net.co/) (of course) * [python-bitcoinrpc](https://pypi.python.org/pypi/python-bitcoinrpc/) * [feedparser](https://pypi.python.org/pypi/feedparser/) -* [gdshortener](https://github.com/torre76/gd_shortener/) (optional) +* URL shortener dependencies (see `use_shortener` at `feedparser.conf.example`) ### Installing diff --git a/feed2twister.conf.example b/feed2twister.conf.example index b434b44..e391898 100644 --- a/feed2twister.conf.example +++ b/feed2twister.conf.example @@ -20,7 +20,13 @@ feeds = https://swatwt.com/favs/rss/en logging_level = debug # we don't want to flood more than that in a single run. max_new_items_per_feed = 3 -# to enable this, you need gdshortener: https://github.com/torre76/gd_shortener/ +# use_shortener (case insensitive): +# * False [default] - no shortener +# * Is.gd [or True (for backward-compatibility)] -- Dependencies: +# * https://github.com/torre76/gd_shortener +# * Ur1.ca [Less tor-hostile] -- Dependencies: +# * https://github.com/legoktm/ur1 +# * https://github.com/MiCHiLU/python-functools32 use_shortener = False # tell is.gd to publicly show statistics for the shortened url shortener_stats = True diff --git a/feed2twister.py b/feed2twister.py index bbfe000..4de1a61 100755 --- a/feed2twister.py +++ b/feed2twister.py @@ -43,14 +43,11 @@ if 'logging_level' in main_config and main_config['logging_level']: logging.basicConfig(level=log_level) -# region shorteners -if 'use_shortener' not in main_config or not main_config['use_shortener']: - shorten = lambda url: url - -shortener = str(main_config['use_shortener']).lower() +# url shorteners +shortener = str(main_config.get('use_shortener', 'false')).lower() -# is.gd is the default -if shortener in ['isgd', 'is.gd', 'gd', 'true', 'yes', 't', '1']: +# is.gd is the default (for historical reasons, but they're tor-user hostile :( ) +if shortener in ['isgd', 'is.gd', 'gd', 'true', 'yes', 'y', '1']: import gdshortener shorten = \ lambda url: gdshortener.ISGDShortener().shorten(url=url, log_stat=get_bool_conf_option('shortener_stats'))[0] @@ -61,8 +58,10 @@ elif shortener in ['v', 'vgd', 'v.gd']: elif shortener in ['ur1', 'ur1.ca', 'ur1ca']: import ur1 shorten = lambda url: ur1.shorten(url) +elif shortener in ['false', 'no', 'n', '0']: + shorten = lambda url: url else: - logging.error('Invalid configuration for "shortener"!') + logging.error('Invalid configuration for "use_shortener"!') sys.exit(10) # endregion