Add stat generator

This commit is contained in:
Robert Miles 2018-06-20 14:54:31 -04:00
parent 9e7d391e3a
commit e02518f419
2 changed files with 28 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
stats.json

27
gen_stats Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
import requests, json
import xml.etree.ElementTree as xml
r = requests.get("http://localhost:8081/stats")
r.raise_for_status()
out = {}
d = xml.fromstring(r.text)
assert d.tag == "inspircdstats"
def define(name,xps,vfilter=lambda x: x):
global out
out[name] = vfilter(d.findall(xps)[0].text)
define("usercount","./general/usercount",int)
define("channelcount","./general/channelcount",int)
schannels = d.findall("./channellist/channel")
#print(len(schannels))
channels = []
for schannel in schannels:
channel = dict(name=schannel.findall("channelname")[0].text,usercount=int(schannel.findall("usercount")[0].text))
channel["topic"] = schannel.findall("./channeltopic/topictext")[0].text if schannel.findall("./channeltopic/topictext")[0].text is not None else "No topic set"
if channel["name"]=="#sudoers": # no stat output for #sudoers! it's a sekrit club of the ~team sysadmins!
continue
channels.append(channel)
out["channels"]=channels
#print([x.text for x in d.findall("./channellist/channel/channeltopic/topictext")])
with open("stats.json","w") as f:
json.dump(out,f)