From a4242090b0e08cecd624ddee6a65ad1ed57d5544 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 16 Mar 2019 14:53:20 -0400 Subject: [PATCH] python3, blacklist --- .gitignore | 1 + README.md | 2 ++ blacklist.example | 2 ++ gen_stats | 12 ++++++++---- 4 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 blacklist.example diff --git a/.gitignore b/.gitignore index ce68d6d..464d994 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ stats.json vendor/ +blacklist diff --git a/README.md b/README.md index 743af1c..270d661 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,5 @@ stop by irc and say hi! `` 4. add gen_stats to a crontab for a user that can write in the webroot: `* * * * * /var/www/tilde.chat/gen_stats` +5. `cp blacklist{.example,}` +6. `vim blacklist` - stats gen will fail if this is missing diff --git a/blacklist.example b/blacklist.example new file mode 100644 index 0000000..7b05f07 --- /dev/null +++ b/blacklist.example @@ -0,0 +1,2 @@ +#mysecrets +#dontlookhere \ No newline at end of file diff --git a/gen_stats b/gen_stats index dc955c8..a53ce1b 100755 --- a/gen_stats +++ b/gen_stats @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import requests, json import xml.etree.ElementTree as xml @@ -8,6 +8,8 @@ out = {} d = xml.fromstring(r.text) assert d.tag == "inspircdstats" +with open("blacklist", "r") as f: + BLACKLIST = f.read().splitlines() def define(name, xps, vfilter=lambda x: x): global out @@ -17,7 +19,7 @@ def define(name, xps, vfilter=lambda x: x): 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( @@ -35,15 +37,17 @@ for schannel in schannels: and channel["topic"] != "No topic set" ): channel["topic"] = "Topic hidden" - if channel["name"] == "#secret-sudoers": - # no stat output for #secret-sudoers! it's a sekrit club of the ~team sysadmins! + if channel["name"] in BLACKLIST: + # skip channels in the blacklist continue channel["webchatlink"] = "https://web.tilde.chat/?join=" + channel["name"].lstrip( "#" ) channels.append(channel) + channels.sort(key=lambda x: x["name"].lower()) out["channels"] = channels + # print([x.text for x in d.findall("./channellist/channel/channeltopic/topictext")]) with open("/var/www/tilde.chat/stats.json", "w") as f: json.dump(out, f)