blob: 5786e8b7302f0e599a481f3c2e90cae8fedb193b (
plain) (
tree)
|
|
import json
default_state = {
'source': 'off',
'source_time': 0,
'title': None,
'welcome': None,
}
def parse_streamers_file(filename):
streamers = {}
with open(filename) as f:
for line in f:
psk, username = line.strip().split(":")
streamers[psk] = username
return streamers
def load_state(filename):
state = dict(default_state)
try:
with open(filename) as f:
state.update(json.load(f))
except FileNotFoundError:
pass
except json.JSONDecodeError:
pass
return state
def save_state(state, filename):
with open(filename, "w") as f:
json.dump(state, f)
def is_banned(ip, filename):
try:
with open(filename) as f:
for line in f:
if line.strip() == ip:
return True
except FileNotFoundError:
pass
return False
def add_ban(ip, filename):
with open(filename, 'a') as f:
f.write(ip + "\n")
|