summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-01-27 11:18:16 +0100
committerLars-Dominik Braun <lars@6xq.net>2019-01-27 11:24:25 +0100
commit668cc5e10c7097d51ba4e4fcae02f55d89283923 (patch)
tree4f21f0b601bbfcfe5f5179c546fc07048c4762a6
parent51d7fa07c5db9a1015ef210089a911c19796bd79 (diff)
downloadcrocoite-668cc5e10c7097d51ba4e4fcae02f55d89283923.tar.gz
crocoite-668cc5e10c7097d51ba4e4fcae02f55d89283923.tar.bz2
crocoite-668cc5e10c7097d51ba4e4fcae02f55d89283923.zip
irc: Switch configuration to JSON
-rw-r--r--README.rst2
-rw-r--r--contrib/chromebot.ini10
-rw-r--r--contrib/chromebot.json12
-rw-r--r--crocoite/cli.py24
4 files changed, 25 insertions, 23 deletions
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 <url> -j <concurrency> -r <policy>
Archive <url> with <concurrency> processes according to recursion <policy>
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 ()