move configs to json

This commit is contained in:
Ben Harris 2019-05-29 22:06:45 -04:00
parent 26ed6b7f09
commit 0d5a6b0106
4 changed files with 19 additions and 10 deletions

1
.gitignore vendored
View File

@ -60,3 +60,4 @@ target/
tildeteam.json tildeteam.json
tildeverse.json tildeverse.json
config.json

7
config.json.example Normal file
View File

@ -0,0 +1,7 @@
{
"channels": [],
"address": "127.0.0.1",
"port": 6667,
"botnick", "tooter"
}

View File

@ -8,17 +8,19 @@ import socket
import sys import sys
from mastodon import Mastodon from mastodon import Mastodon
server = ("127.0.0.1", 6667) path = os.path.dirname(os.path.abspath(__file__))
channels = []
with open(os.path.join(path, "config.json")) as f:
config = json.load(f)
botnick = config["botnick"]
channels = config["channels"]
if len(sys.argv) > 1: if len(sys.argv) > 1:
for c in sys.argv[1:]: for c in sys.argv[1:]:
channels.append("#" + c) channels.append("#" + c)
botnick = "tooter"
# read masto creds # read masto creds
path = os.path.dirname(os.path.abspath(__file__)) with open(os.path.join(path, "tildeverse.json")) as f:
tildeverse_file = os.path.join(path, "tildeverse.json")
with open(tildeverse_file) as f:
tildeverse_config = json.load(f) tildeverse_config = json.load(f)
tildeverse = Mastodon( tildeverse = Mastodon(
@ -28,8 +30,7 @@ tildeverse = Mastodon(
api_base_url=tildeverse_config["base_url"], api_base_url=tildeverse_config["base_url"],
) )
tildeteam_file = os.path.join(path, "tildeteam.json") with open(os.path.join(path, "tildeteam.json")) as f:
with open(tildeteam_file) as f:
tildeteam_config = json.load(f) tildeteam_config = json.load(f)
tildeteam = Mastodon( tildeteam = Mastodon(
@ -72,7 +73,7 @@ def eventloop(chan, nick, msg):
if __name__ == "__main__": if __name__ == "__main__":
ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ircsock.connect(server) ircsock.connect((config["address"], config["port"]))
rawsend(f"NICK {botnick}") rawsend(f"NICK {botnick}")
rawsend(f"USER {botnick} 0 * :mastodon tooter") rawsend(f"USER {botnick} 0 * :mastodon tooter")

View File

@ -5,7 +5,7 @@ After=tooter.service
[Service] [Service]
Type=simple Type=simple
WorkingDirectory=/home/ben/workspace/tooter WorkingDirectory=/home/ben/workspace/tooter
ExecStart=/home/ben/workspace/tracer/tooter.py ExecStart=/home/ben/workspace/tooter/tooter.py
Restart=always Restart=always
RestartSec=5 RestartSec=5
StartLimitInterval=60s StartLimitInterval=60s