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 == '':
|
||||
|
||||
toot_text += f"\nServer not found but it's alive. Added!\n\n"
|
||||
|
||||
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}'
|
||||
|
||||
|
|
79
query.py
79
query.py
|
@ -37,11 +37,16 @@ class Query():
|
|||
|
||||
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.db = Database()
|
||||
self.setup = Setup()
|
||||
self.soft = ''
|
||||
self.soft_version = ''
|
||||
self.users = 0
|
||||
self.mau = 0
|
||||
self.alive = alive
|
||||
|
||||
def getsoft(self, server):
|
||||
|
||||
|
@ -54,8 +59,6 @@ class Query():
|
|||
if server.find(":") != -1:
|
||||
return
|
||||
|
||||
soft = ''
|
||||
|
||||
is_nodeinfo = False
|
||||
|
||||
url = 'https://' + server
|
||||
|
@ -196,22 +199,22 @@ class Query():
|
|||
|
||||
try:
|
||||
|
||||
soft = nodeinfo_json['software']['name']
|
||||
soft = soft.lower()
|
||||
soft_version = nodeinfo_json['software']['version']
|
||||
users = nodeinfo_json.get('usage').get('users').get('total') or '0'
|
||||
if users > 1000000:
|
||||
self.soft = nodeinfo_json['software']['name']
|
||||
self.soft = self.soft.lower()
|
||||
self.soft_version = nodeinfo_json['software']['version']
|
||||
self.users = nodeinfo_json.get('usage').get('users').get('total') or '0'
|
||||
if self.users > 1000000:
|
||||
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('*********************************************************************')
|
||||
|
||||
return (server, soft, soft_version, users, mau, alive)
|
||||
return (server, self.soft, self.soft_version, self.users, self.mau, self.alive)
|
||||
|
||||
except:
|
||||
|
||||
|
@ -221,22 +224,22 @@ class Query():
|
|||
|
||||
try:
|
||||
|
||||
soft = nodeinfo_json['server']['software']
|
||||
soft = soft.lower()
|
||||
soft_version = nodeinfo_json['server']['version']
|
||||
users = nodeinfo_json['usage']['users']['total']
|
||||
if users > 1000000:
|
||||
self.soft = nodeinfo_json['server']['software']
|
||||
self.soft = soft.lower()
|
||||
self.soft_version = nodeinfo_json['server']['version']
|
||||
self.users = nodeinfo_json['usage']['users']['total']
|
||||
if self.users > 1000000:
|
||||
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)
|
||||
|
||||
print('*********************************************************************')
|
||||
print(f"Server {serve}r ({soft} {soft_version}) is alive!")
|
||||
print(f"Server {server} ({self.soft} {self.soft_version}) is alive!")
|
||||
print('*********************************************************************')
|
||||
|
||||
return
|
||||
|
@ -245,53 +248,53 @@ class Query():
|
|||
|
||||
pass
|
||||
|
||||
if soft == '' and nodeinfo == "/api/v1/instance?":
|
||||
if self.soft == '' and nodeinfo == "/api/v1/instance?":
|
||||
|
||||
soft = 'mastodon'
|
||||
self.soft = 'mastodon'
|
||||
|
||||
try:
|
||||
|
||||
users = nodeinfo_json['stats']['user_count']
|
||||
self.users = nodeinfo_json['stats']['user_count']
|
||||
|
||||
if users > 1000000:
|
||||
if self.users > 1000000:
|
||||
|
||||
return
|
||||
|
||||
except:
|
||||
|
||||
users = 0
|
||||
self.users = 0
|
||||
|
||||
try:
|
||||
|
||||
soft_version = nodeinfo_json['version']
|
||||
self.soft_version = nodeinfo_json['version']
|
||||
|
||||
except:
|
||||
|
||||
soft_version = 'unknown'
|
||||
self.soft_version = 'unknown'
|
||||
|
||||
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(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'
|
||||
users = nodeinfo_json['stats']['user_count']
|
||||
soft_version = nodeinfo_json['version']
|
||||
alive = True
|
||||
self.soft = 'zap'
|
||||
self.users = nodeinfo_json['stats']['user_count']
|
||||
self.soft_version = nodeinfo_json['version']
|
||||
self.alive = True
|
||||
|
||||
print(server, soft, users, alive, api)
|
||||
print(server, self.soft, self.users, self.alive, api)
|
||||
|
||||
print('*********************************************************************')
|
||||
print(f"Server {server} ({soft}) is alive!")
|
||||
print(f"Server {server} ({self.soft}) is alive!")
|
||||
|
||||
else:
|
||||
|
||||
print(f'Server {server} is dead')
|
||||
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