tidy up script
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
034e963ade
commit
2830cd000d
37
gen_stats
37
gen_stats
|
@ -15,11 +15,6 @@ with open(f"{WORK_DIR}/blacklist", "r") as f:
|
|||
BLACKLIST = f.read().splitlines()
|
||||
|
||||
|
||||
def define(name, xps, vfilter=lambda x: x):
|
||||
global out
|
||||
out[name] = vfilter(root.findall(xps)[0].text)
|
||||
|
||||
|
||||
def unsanitize(node, default=""):
|
||||
# workaround for weird behavior in insp's xml output
|
||||
# https://github.com/inspircd/inspircd/blob/v3.7.0/src/modules/m_httpd_stats.cpp#L55
|
||||
|
@ -36,29 +31,31 @@ def unsanitize(node, default=""):
|
|||
return node.text
|
||||
|
||||
|
||||
define("usercount", "./general/usercount", int)
|
||||
define("channelcount", "./general/channelcount", int)
|
||||
schannels = root.findall("./channellist/channel")
|
||||
out["usercount"] = int(root.find("./general/usercount").text)
|
||||
out["channelcount"] = int(root.find("./general/channelcount").text)
|
||||
|
||||
channels = []
|
||||
for schannel in schannels:
|
||||
channel = {}
|
||||
channel["name"] = unsanitize(schannel.find("channelname"))
|
||||
channel["topic"] = unsanitize(schannel.find("./channeltopic/topictext"), "no topic set")
|
||||
channel["usercount"] = int(schannel.find("usercount").text)
|
||||
channel["webchatlink"] = "https://web.tilde.chat/?join=" + quote(channel["name"])
|
||||
out["channels"] = []
|
||||
for c in root.findall("./channellist/channel"):
|
||||
name = unsanitize(c.find("channelname"))
|
||||
|
||||
if (
|
||||
# skip channels in the blacklist or with mode +s
|
||||
"s" in schannel.find("./channelmodes").text.split()[0]
|
||||
or channel["name"] in BLACKLIST
|
||||
"s" in c.find("./channelmodes").text.split()[0]
|
||||
or name in BLACKLIST
|
||||
):
|
||||
continue
|
||||
|
||||
channels.append(channel)
|
||||
out["channels"].append(
|
||||
dict(
|
||||
name=name,
|
||||
topic=unsanitize(c.find("./channeltopic/topictext"), "no topic set"),
|
||||
usercount=int(c.find("usercount").text),
|
||||
webchatlink="https://web.tilde.chat/?join=" + quote(name),
|
||||
)
|
||||
)
|
||||
|
||||
channels.sort(key=lambda x: x["name"].lower())
|
||||
out["channels"] = channels
|
||||
|
||||
out["channels"].sort(key=lambda x: x["name"].lower())
|
||||
|
||||
with open(f"{WORK_DIR}/stats.json", "w") as f:
|
||||
json.dump(out, f)
|
||||
|
|
Loading…
Reference in New Issue