python3, blacklist
This commit is contained in:
parent
cd4b8ab8a6
commit
a4242090b0
|
@ -1,2 +1,3 @@
|
||||||
stats.json
|
stats.json
|
||||||
vendor/
|
vendor/
|
||||||
|
blacklist
|
||||||
|
|
|
@ -19,3 +19,5 @@ stop by irc and say hi!
|
||||||
`<bind address="127.0.0.1" port="8081" type="httpd">`
|
`<bind address="127.0.0.1" port="8081" type="httpd">`
|
||||||
4. add gen_stats to a crontab for a user that can write in the webroot:
|
4. add gen_stats to a crontab for a user that can write in the webroot:
|
||||||
`* * * * * /var/www/tilde.chat/gen_stats`
|
`* * * * * /var/www/tilde.chat/gen_stats`
|
||||||
|
5. `cp blacklist{.example,}`
|
||||||
|
6. `vim blacklist` - stats gen will fail if this is missing
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#mysecrets
|
||||||
|
#dontlookhere
|
12
gen_stats
12
gen_stats
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import requests, json
|
import requests, json
|
||||||
import xml.etree.ElementTree as xml
|
import xml.etree.ElementTree as xml
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ out = {}
|
||||||
d = xml.fromstring(r.text)
|
d = xml.fromstring(r.text)
|
||||||
assert d.tag == "inspircdstats"
|
assert d.tag == "inspircdstats"
|
||||||
|
|
||||||
|
with open("blacklist", "r") as f:
|
||||||
|
BLACKLIST = f.read().splitlines()
|
||||||
|
|
||||||
def define(name, xps, vfilter=lambda x: x):
|
def define(name, xps, vfilter=lambda x: x):
|
||||||
global out
|
global out
|
||||||
|
@ -17,7 +19,7 @@ def define(name, xps, vfilter=lambda x: x):
|
||||||
define("usercount", "./general/usercount", int)
|
define("usercount", "./general/usercount", int)
|
||||||
define("channelcount", "./general/channelcount", int)
|
define("channelcount", "./general/channelcount", int)
|
||||||
schannels = d.findall("./channellist/channel")
|
schannels = d.findall("./channellist/channel")
|
||||||
# print(len(schannels))
|
|
||||||
channels = []
|
channels = []
|
||||||
for schannel in schannels:
|
for schannel in schannels:
|
||||||
channel = dict(
|
channel = dict(
|
||||||
|
@ -35,15 +37,17 @@ for schannel in schannels:
|
||||||
and channel["topic"] != "No topic set"
|
and channel["topic"] != "No topic set"
|
||||||
):
|
):
|
||||||
channel["topic"] = "Topic hidden"
|
channel["topic"] = "Topic hidden"
|
||||||
if channel["name"] == "#secret-sudoers":
|
if channel["name"] in BLACKLIST:
|
||||||
# no stat output for #secret-sudoers! it's a sekrit club of the ~team sysadmins!
|
# skip channels in the blacklist
|
||||||
continue
|
continue
|
||||||
channel["webchatlink"] = "https://web.tilde.chat/?join=" + channel["name"].lstrip(
|
channel["webchatlink"] = "https://web.tilde.chat/?join=" + channel["name"].lstrip(
|
||||||
"#"
|
"#"
|
||||||
)
|
)
|
||||||
channels.append(channel)
|
channels.append(channel)
|
||||||
|
|
||||||
channels.sort(key=lambda x: x["name"].lower())
|
channels.sort(key=lambda x: x["name"].lower())
|
||||||
out["channels"] = channels
|
out["channels"] = channels
|
||||||
|
|
||||||
# print([x.text for x in d.findall("./channellist/channel/channeltopic/topictext")])
|
# print([x.text for x in d.findall("./channellist/channel/channeltopic/topictext")])
|
||||||
with open("/var/www/tilde.chat/stats.json", "w") as f:
|
with open("/var/www/tilde.chat/stats.json", "w") as f:
|
||||||
json.dump(out, f)
|
json.dump(out, f)
|
||||||
|
|
Loading…
Reference in New Issue