Backward compatibility on N parameters. No more required to first cd to the feed2twister folder.

This commit is contained in:
Étienne Deparis 2014-10-13 16:32:37 +02:00
parent 4519800066
commit 3712d913b1
3 changed files with 9 additions and 5 deletions

View File

@ -2,6 +2,7 @@ Feed2twister is a simple script to post items from RSS/ATOM feeds to [Twister](h
### Prerequisites ### Prerequisites
* Python 2
* [Twister](http://twister.net.co/) (of course) * [Twister](http://twister.net.co/) (of course)
* [python-bitcoinrpc](https://pypi.python.org/pypi/python-bitcoinrpc/) * [python-bitcoinrpc](https://pypi.python.org/pypi/python-bitcoinrpc/)
* [feedparser](https://pypi.python.org/pypi/feedparser/) * [feedparser](https://pypi.python.org/pypi/feedparser/)
@ -19,7 +20,7 @@ Feed2twister is a simple script to post items from RSS/ATOM feeds to [Twister](h
### Running ### Running
Normally, you would run this as a cron task: `cd /path/to/this ; python feed2twister.py` [`-n N`] [`-c CONFIGFILE`] Normally, you would run this as a cron task: `/path/to/this/feed2twister.py [N] [-c CONFIGFILE]`
if [optional] `N` is supplied, it's used as the maximum items to post (per feed). Default is `0`. if [optional] `N` is supplied, it's used as the maximum items to post (per feed). Default is `0`.
@ -28,4 +29,4 @@ If there are more than `N` new items in a feed, "over quota" items get marked as
Specifically, `python feed2twister.py 0` would make all feeds "catch up" without posting anything. Specifically, `python feed2twister.py 0` would make all feeds "catch up" without posting anything.
if [optional] `CONFIGFILE` is supplied, it is used as a custom config file, instead of the first file found in the following list: ./feed2twister.conf, ~/.config/feed2twister.conf, ~/.feed2twister.conf if [optional] `CONFIGFILE` is supplied, it is used as a custom config file, instead of the first file found in the following list: `./feed2twister.conf`, `~/.config/feed2twister.conf`, `~/.feed2twister.conf`

View File

@ -4,7 +4,7 @@ username = MYTWISTERUSERNAME
# change to rpcuser and rpcpassword from ~/.twister/twister.conf # change to rpcuser and rpcpassword from ~/.twister/twister.conf
rpc_url = http://MYRPCUSER:MYRPCPASSWORD@127.0.0.1:28332 rpc_url = http://MYRPCUSER:MYRPCPASSWORD@127.0.0.1:28332
# db is mainly there to keep track of "what not to post again" :) (debugging too, I guess) # db is mainly there to keep track of "what not to post again" :) (debugging too, I guess)
db_filename = items.db db_filename = ~/.feed2twister.db
# this leaves 36 characters and a ... to get to 140. If we don't have that, we skip the item :( # this leaves 36 characters and a ... to get to 140. If we don't have that, we skip the item :(
max_url_length = 100 max_url_length = 100
# Use your own feeds, of course :) # Use your own feeds, of course :)

7
feed2twister.py Normal file → Executable file
View File

@ -1,3 +1,6 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import os,feedparser,anydbm,argparse,ConfigParser import os,feedparser,anydbm,argparse,ConfigParser
from bitcoinrpc.authproxy import AuthServiceProxy from bitcoinrpc.authproxy import AuthServiceProxy
@ -5,7 +8,7 @@ SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
arg_parser = argparse.ArgumentParser(description='Feed2twister is a simple script to post items from RSS/ATOM feeds to Twister.') arg_parser = argparse.ArgumentParser(description='Feed2twister is a simple script to post items from RSS/ATOM feeds to Twister.')
arg_parser.add_argument('--config', '-c', help='Alternate config file. Default is {0}.'.format(os.path.join(SCRIPT_PATH, 'feed2twister.conf'))) arg_parser.add_argument('--config', '-c', help='Alternate config file. Default is {0}.'.format(os.path.join(SCRIPT_PATH, 'feed2twister.conf')))
arg_parser.add_argument('--maxitems', '-n', type=int, metavar='N', arg_parser.add_argument('maxitems', metavar='N', type=int, nargs='?', default=None,
help="""Maximum items to post (per feed). Default is 0. help="""Maximum items to post (per feed). Default is 0.
If there are more than N new items in a feed, "over quota" items get marked as if they were posted (this can be handy when you add a new feed with a long history). Specifically, %(prog)s 0 would make all feeds "catch up" without posting anything.""") If there are more than N new items in a feed, "over quota" items get marked as if they were posted (this can be handy when you add a new feed with a long history). Specifically, %(prog)s 0 would make all feeds "catch up" without posting anything.""")
args = arg_parser.parse_args() args = arg_parser.parse_args()
@ -67,7 +70,7 @@ def get_next_k(twister,username):
return 0 return 0
def main(max_items): def main(max_items):
db = anydbm.open(main_config['db_filename'],'c') db = anydbm.open(os.path.expanduser(main_config['db_filename']),'c')
twister = AuthServiceProxy(main_config['rpc_url']) twister = AuthServiceProxy(main_config['rpc_url'])
for feed_url in get_array_conf_option('feeds'): for feed_url in get_array_conf_option('feeds'):