Implement API endpoint for network listing
This commit is contained in:
33
api/views.py
33
api/views.py
@@ -157,3 +157,36 @@ class API(object):
|
||||
results = userinfo.getChanNum(net, data["query"])
|
||||
|
||||
return dumps(results)
|
||||
|
||||
@app.route("/irc/stats/", methods=["POST"])
|
||||
@login_required
|
||||
def irc_stats(self, request):
|
||||
stats = {}
|
||||
numChannels = 0
|
||||
numWhoEntries = 0
|
||||
for i in main.IRCPool.keys():
|
||||
numChannels += len(main.IRCPool[i].channels)
|
||||
numWhoEntries += userinfo.getNumTotalWhoEntries()
|
||||
numRelays = 0
|
||||
for net in main.network.keys():
|
||||
numRelays += len(main.network[net].relays)
|
||||
stats["servers_total_total"] = numRelays
|
||||
stats["servers_total_unique"] = len(main.network.keys())
|
||||
stats["servers_online_total"] = len(main.IRCPool.keys())
|
||||
stats["servers_online_unique"] = len(main.liveNets())
|
||||
stats["channels"] = numChannels
|
||||
stats["records"] = numWhoEntries
|
||||
stats["eventrate"] = main.lastMinuteSample
|
||||
return dumps(stats)
|
||||
|
||||
@app.route("/irc/networks/", methods=["POST"])
|
||||
@login_required
|
||||
def irc_networks(self, request):
|
||||
networks = {}
|
||||
for net in main.network.keys():
|
||||
networks[net] = {
|
||||
"relays": len(main.network[net].relays),
|
||||
"channels": userinfo.getTotalChanNum(net),
|
||||
"records": userinfo.getNumWhoEntries(net),
|
||||
}
|
||||
return dumps(networks)
|
||||
|
||||
Reference in New Issue
Block a user