Fix #7
This commit is contained in:
pare
a9f319c958
commit
469488393a
S'han modificat 2 arxius amb 46 adicions i 41 eliminacions
|
@ -162,11 +162,13 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
if server == '':
|
if server == '':
|
||||||
|
|
||||||
toot_text += f"\nServer not found but it's alive. Added!\n\n"
|
|
||||||
|
|
||||||
server, software, version, users, mau, alive = query.getsoft(search_server)
|
server, software, version, users, mau, alive = query.getsoft(search_server)
|
||||||
|
|
||||||
if server != '':
|
if server != '' and alive:
|
||||||
|
|
||||||
|
toot_text += f"\nServer not found but it's alive. Added!\n\n"
|
||||||
|
|
||||||
|
if alive:
|
||||||
|
|
||||||
toot_text += f'server: {server}\nsoftware: :{software}:\nversion: {version}\nMAU: {mau:,}\nusers: {users:,}\nalive: {alive}'
|
toot_text += f'server: {server}\nsoftware: :{software}:\nversion: {version}\nMAU: {mau:,}\nusers: {users:,}\nalive: {alive}'
|
||||||
|
|
||||||
|
|
79
query.py
79
query.py
|
@ -37,11 +37,16 @@ class Query():
|
||||||
|
|
||||||
name = "Query server data"
|
name = "Query server data"
|
||||||
|
|
||||||
def __init__(self, server=None, db=None, setup=None):
|
def __init__(self, server=None, db=None, setup=None, soft=None, soft_version=None, version=None, users=None, mau=None, alive=False):
|
||||||
|
|
||||||
self.server = server
|
self.server = server
|
||||||
self.db = Database()
|
self.db = Database()
|
||||||
self.setup = Setup()
|
self.setup = Setup()
|
||||||
|
self.soft = ''
|
||||||
|
self.soft_version = ''
|
||||||
|
self.users = 0
|
||||||
|
self.mau = 0
|
||||||
|
self.alive = alive
|
||||||
|
|
||||||
def getsoft(self, server):
|
def getsoft(self, server):
|
||||||
|
|
||||||
|
@ -54,8 +59,6 @@ class Query():
|
||||||
if server.find(":") != -1:
|
if server.find(":") != -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
soft = ''
|
|
||||||
|
|
||||||
is_nodeinfo = False
|
is_nodeinfo = False
|
||||||
|
|
||||||
url = 'https://' + server
|
url = 'https://' + server
|
||||||
|
@ -196,22 +199,22 @@ class Query():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
soft = nodeinfo_json['software']['name']
|
self.soft = nodeinfo_json['software']['name']
|
||||||
soft = soft.lower()
|
self.soft = self.soft.lower()
|
||||||
soft_version = nodeinfo_json['software']['version']
|
self.soft_version = nodeinfo_json['software']['version']
|
||||||
users = nodeinfo_json.get('usage').get('users').get('total') or '0'
|
self.users = nodeinfo_json.get('usage').get('users').get('total') or '0'
|
||||||
if users > 1000000:
|
if self.users > 1000000:
|
||||||
return
|
return
|
||||||
mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
||||||
|
|
||||||
alive = True
|
self.alive = True
|
||||||
|
|
||||||
self.db.write_api(server, soft, users, alive, nodeinfo, soft_version)
|
self.db.write_api(server, self.soft, self.users, self.alive, nodeinfo, self.soft_version)
|
||||||
|
|
||||||
print(f"Server {server} ({soft} {soft_version}) is alive!")
|
print(f"Server {server} ({soft} {soft_version}) is alive!")
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
|
|
||||||
return (server, soft, soft_version, users, mau, alive)
|
return (server, self.soft, self.soft_version, self.users, self.mau, self.alive)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
||||||
|
@ -221,22 +224,22 @@ class Query():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
soft = nodeinfo_json['server']['software']
|
self.soft = nodeinfo_json['server']['software']
|
||||||
soft = soft.lower()
|
self.soft = soft.lower()
|
||||||
soft_version = nodeinfo_json['server']['version']
|
self.soft_version = nodeinfo_json['server']['version']
|
||||||
users = nodeinfo_json['usage']['users']['total']
|
self.users = nodeinfo_json['usage']['users']['total']
|
||||||
if users > 1000000:
|
if self.users > 1000000:
|
||||||
return
|
return
|
||||||
mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
||||||
|
|
||||||
alive = True
|
self.alive = True
|
||||||
|
|
||||||
if soft == 'socialhome':
|
if self.soft == 'socialhome':
|
||||||
|
|
||||||
self.db.write_api(server, soft, users, alive, nodeinfo, soft_version)
|
self.db.write_api(server, soft, users, alive, nodeinfo, soft_version)
|
||||||
|
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
print(f"Server {serve}r ({soft} {soft_version}) is alive!")
|
print(f"Server {server} ({self.soft} {self.soft_version}) is alive!")
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -245,53 +248,53 @@ class Query():
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if soft == '' and nodeinfo == "/api/v1/instance?":
|
if self.soft == '' and nodeinfo == "/api/v1/instance?":
|
||||||
|
|
||||||
soft = 'mastodon'
|
self.soft = 'mastodon'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
users = nodeinfo_json['stats']['user_count']
|
self.users = nodeinfo_json['stats']['user_count']
|
||||||
|
|
||||||
if users > 1000000:
|
if self.users > 1000000:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
||||||
users = 0
|
self.users = 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
soft_version = nodeinfo_json['version']
|
self.soft_version = nodeinfo_json['version']
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
||||||
soft_version = 'unknown'
|
self.soft_version = 'unknown'
|
||||||
|
|
||||||
alive = True
|
alive = True
|
||||||
|
|
||||||
self.db.write_api(server, soft, users, alive, nodeinfo, soft_version)
|
self.db.write_api(server, self.soft, self.users, self.alive, nodeinfo, self.soft_version)
|
||||||
|
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
print(f"Server {server} ({soft}) is alive!")
|
print(f"Server {server} ({self.soft}) is alive!")
|
||||||
|
|
||||||
elif soft == 'zap' and nodeinfo == "/api/v1/instance?":
|
elif self.soft == 'zap' and nodeinfo == "/api/v1/instance?":
|
||||||
|
|
||||||
soft = 'zap'
|
self.soft = 'zap'
|
||||||
users = nodeinfo_json['stats']['user_count']
|
self.users = nodeinfo_json['stats']['user_count']
|
||||||
soft_version = nodeinfo_json['version']
|
self.soft_version = nodeinfo_json['version']
|
||||||
alive = True
|
self.alive = True
|
||||||
|
|
||||||
print(server, soft, users, alive, api)
|
print(server, self.soft, self.users, self.alive, api)
|
||||||
|
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
print(f"Server {server} ({soft}) is alive!")
|
print(f"Server {server} ({self.soft}) is alive!")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
print(f'Server {server} is dead')
|
print(f'Server {server} is dead')
|
||||||
print('*********************************************************************')
|
print('*********************************************************************')
|
||||||
|
|
||||||
return (server, software, version, users, mau, alive)
|
return (server, self.soft, self.soft_version, self.users, self.mau, self.alive)
|
||||||
|
|
||||||
|
|
Loading…
Referencia en una nova incidència