Allow conf_file to be the JSON data directly

Easier for containers
pull/315/merge
Mike Lang 1 year ago committed by Mike Lang
parent 8813068c9d
commit 05d5a190fc

@ -0,0 +1,12 @@
import json
import yaml
def get_config(conf_file):
if conf_file.startswith("{"):
return json.loads(conf_file)
else:
with open(conf_file) as f:
return yaml.safe_load(f)

@ -9,9 +9,9 @@ from datetime import datetime, timedelta
import gevent.pool import gevent.pool
import argh import argh
import yaml
from zulip import Client from zulip import Client
from config import get_config
logging.basicConfig(level='INFO') logging.basicConfig(level='INFO')
@ -203,8 +203,7 @@ def main(conf_file, hour=-1, no_groups=False, stream="General", no_mentions=Fals
NAME: GROUP_ID NAME: GROUP_ID
authentication is an object {email, api_key} authentication is an object {email, api_key}
""" """
with open(conf_file) as f: config = get_config(conf_file)
config = yaml.safe_load(f)
client = Client(config["url"], config["api_user"]["email"], config["api_user"]["api_key"]) client = Client(config["url"], config["api_user"]["email"], config["api_user"]["api_key"])
send_auth = config.get("send_user", config["api_user"]) send_auth = config.get("send_user", config["api_user"])
send_client = Client(config["url"], send_auth["email"], send_auth["api_key"]) send_client = Client(config["url"], send_auth["email"], send_auth["api_key"])

@ -5,19 +5,14 @@ import logging
import time import time
import mastodon import mastodon
import yaml
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import zulip import zulip
from config import get_config
cli = argh.EntryPoint() cli = argh.EntryPoint()
def get_config(conf_file):
with open(conf_file) as f:
return yaml.safe_load(f)
def format_account(account): def format_account(account):
return f"**[{account['display_name']}]({account['url']})**" return f"**[{account['display_name']}]({account['url']})**"

@ -6,9 +6,9 @@ import logging
import argh import argh
import girc import girc
import yaml
import zulip import zulip
from config import get_config
def run(zulip_client, nick, oauth_token, stream, topic): def run(zulip_client, nick, oauth_token, stream, topic):
@ -49,8 +49,7 @@ def main(conf_file, stream="bot-spam", topic="Twitch DMs", retry_interval=10):
""" """
logging.basicConfig(level='INFO') logging.basicConfig(level='INFO')
with open(conf_file) as f: config = get_config(conf_file)
config = yaml.safe_load(f)
zulip_client = zulip.Client(config["zulip_url"], config["zulip_email"], config["zulip_api_key"]) zulip_client = zulip.Client(config["zulip_url"], config["zulip_email"], config["zulip_api_key"])

Loading…
Cancel
Save