-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.py
43 lines (32 loc) · 1 KB
/
init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import json
from os.path import expanduser
from irc import IRC
# config path
cfg_path = "~/.ramenbot/ramenrc.json"
if len(sys.argv) >= 2:
cfg_path = sys.argv[1]
# get config from json file
try:
fd = open(expanduser(cfg_path), 'r')
config = json.load(fd)
except FileNotFoundError as err:
print("Configuration file not found [{0}]".format(cfg_path), file=sys.stderr)
sys.exit(2)
except json.decoder.JSONDecodeError:
print("Provide a valid json file as configuration", file=sys.stderr)
sys.exit(1)
# try to connect to server
try:
irc = IRC(host=config['host'], port=config['port'], nick=config['nick'], channels=config['channels'], database=config['db'],
ssl=config['ssl'], prefix=config['prefix'], password=config['password'])
irc.connect()
except KeyError:
print("The configuration provided is not valid")
sys.exit(1)
except KeyboardInterrupt:
# terminar conexion con db y servidor!!
print("Goodbye ;-)")
sys.exit(0)
except:
raise