From 668cc5e10c7097d51ba4e4fcae02f55d89283923 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 27 Jan 2019 11:18:16 +0100 Subject: irc: Switch configuration to JSON --- README.rst | 2 +- contrib/chromebot.ini | 10 ---------- contrib/chromebot.json | 12 ++++++++++++ crocoite/cli.py | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 23 deletions(-) delete mode 100644 contrib/chromebot.ini create mode 100644 contrib/chromebot.json diff --git a/README.rst b/README.rst index 45d2e0f..581ac13 100644 --- a/README.rst +++ b/README.rst @@ -163,7 +163,7 @@ IRC bot A simple IRC bot (“chromebot”) is provided with the command ``crocoite-irc``. It reads its configuration from a config file like the example provided in -``contrib/chromebot.ini`` and supports the following commands: +``contrib/chromebot.json`` and supports the following commands: a -j -r Archive with processes according to recursion diff --git a/contrib/chromebot.ini b/contrib/chromebot.ini deleted file mode 100644 index a302356..0000000 --- a/contrib/chromebot.ini +++ /dev/null @@ -1,10 +0,0 @@ -[irc] -host = irc.example.com -port = 6667 -ssl = False -tempdir = /path/to/warc -destdir = /path/to/tmp -nick = chromebot -channel = #testchannel -process_limit = 1 - diff --git a/contrib/chromebot.json b/contrib/chromebot.json new file mode 100644 index 0000000..98a48f9 --- /dev/null +++ b/contrib/chromebot.json @@ -0,0 +1,12 @@ +{ + "irc": { + "host": "irc.example.com", + "port": 6667, + "ssl": false, + "nick": "chromebot", + "channels": ["#testchannel"] + }, + "tempdir": "/path/to/tmp", + "destdir": "/path/to/warc", + "process_limit": 1 +} diff --git a/crocoite/cli.py b/crocoite/cli.py index a8de73b..b73051b 100644 --- a/crocoite/cli.py +++ b/crocoite/cli.py @@ -132,30 +132,30 @@ def recursive (): return 0 def irc (): - from configparser import ConfigParser + import json from .irc import Chromebot logger = Logger (consumer=[DatetimeConsumer (), JsonPrintConsumer ()]) parser = argparse.ArgumentParser(description='IRC bot.') - parser.add_argument('--config', '-c', help='Config file location', metavar='PATH', default='chromebot.ini') + parser.add_argument('--config', '-c', help='Config file location', metavar='PATH', default='chromebot.json') args = parser.parse_args () - config = ConfigParser () - config.read (args.config) + with open (args.config) as fd: + config = json.load (fd) s = config['irc'] loop = asyncio.get_event_loop() bot = Chromebot ( - host=s.get ('host'), - port=s.getint ('port'), - ssl=s.getboolean ('ssl'), - nick=s.get ('nick'), - channels=[s.get ('channel')], - tempdir=s.get ('tempdir'), - destdir=s.get ('destdir'), - processLimit=s.getint ('process_limit'), + host=s['host'], + port=s['port'], + ssl=s['ssl'], + nick=s['nick'], + channels=s['channels'], + tempdir=config['tempdir'], + destdir=config['destdir'], + processLimit=config['process_limit'], logger=logger, loop=loop) stop = lambda signum: bot.cancel () -- cgit v1.2.3