From 5288dde45932730bb3109534d63ebba1b2b4d71f Mon Sep 17 00:00:00 2001 From: spla Date: Thu, 4 Jun 2020 19:38:53 +0200 Subject: [PATCH] set alive = True if API is replying --- fediverse.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fediverse.py b/fediverse.py index 25dca71..35f87eb 100644 --- a/fediverse.py +++ b/fediverse.py @@ -102,45 +102,47 @@ def alive_server(server, x): if serv_api == '/nodeinfo/2.0?': try: users = data.json()['usage']['users']['total'] + alive = True except: users = 0 if serv_api == '/nodeinfo/2.0.json?': try: users = data.json()['usage']['users']['total'] + alive = True except: users = 0 elif serv_api == '/api/v1/instance?': try: users = data.json()['stats']['user_count'] + alive = True except: users = 0 - alive = True if serv_soft == "pleroma" or serv_soft == "diaspora" or serv_soft == "peertube" or serv_soft == "pixelfed" or serv_soft == "hubzilla" or serv_soft == "writefreely" or serv_soft == "friendica": try: users = data.json()['usage']['users']['total'] + alive = True except: users = 0 - alive = True if serv_soft == "gnusocialv2" or serv_soft == "gnusocial": try: users = data.json()['usage']['users']['total'] if users == 0: users = data.json()['usage']['users']['activeHalfyear'] + alive = True except: users = 0 - alive = True if serv_soft == "plume" or serv_soft == 'red' or serv_soft == "misskey" or serv_soft == "zap" or serv_soft == "prismo" or serv_soft == "ravenvale" or serv_soft == "osada" or serv_soft == "groundpolis": try: users = data.json()['usage']['users']['total'] + alive = True except: users = 0 - alive = True if serv_soft == "ganggo" or serv_soft == "squs" or serv_soft == "dolphin": try: users = data.json()['usage']['users']['total'] + alive = True except: users = 0 - alive = True print("Server " + str(server) + " (" + serv_soft + ") is alive!") @@ -274,11 +276,13 @@ def write_api(server, software, users, alive, api): cur.close() except (Exception, psycopg2.DatabaseError) as error: + print(error) finally: if conn is not None: + conn.close() async def getsoft(server): @@ -551,8 +555,8 @@ if __name__ == '__main__': ########################################################################### # get current total servers and users, get users from every software - gettotals_sql = "select count(server), sum(users) from fediverse" - get_soft_totals_sql = "select software, sum(users) as users, count(server) as servers from fediverse where users != 0 group by software order by users desc" + gettotals_sql = "select count(server), sum(users) from fediverse where alive" + get_soft_totals_sql = "select software, sum(users) as users, count(server) as servers from fediverse where users != 0 and alive group by software order by users desc" soft_total_project = [] soft_total_users = [] soft_total_servers = []