Save MAU to database

This commit is contained in:
spla 2023-01-08 10:55:24 +01:00
pare 5c439bdf86
commit 60da5d7a88
S'han modificat 4 arxius amb 14 adicions i 12 eliminacions

Veure arxiu

@ -32,3 +32,4 @@ Within Python Virtual Environment:
4.1.2023 - Now peers are obtained from mastodon.social's peers list. 4.1.2023 - Now peers are obtained from mastodon.social's peers list.
5.1.2023 - Added fediquery.py. Allow ask the main bot fediverse about `soft` and `server` and it replies to the asking user with its data if any. 5.1.2023 - Added fediquery.py. Allow ask the main bot fediverse about `soft` and `server` and it replies to the asking user with its data if any.
7.1.2023 - When querying a not found server, we will be added to database if it's alive. 7.1.2023 - When querying a not found server, we will be added to database if it's alive.
8.1.2023 - Save MAU to database.

Veure arxiu

@ -95,11 +95,11 @@ class Database():
conn.close() conn.close()
def write_api(self, server, software, users, alive, api, soft_version): def write_api(self, server, software, users, mau, alive, api, soft_version):
now = datetime.now() now = datetime.now()
insert_sql = "INSERT INTO fediverse(server, updated_at, software, users, alive, users_api, version) VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING" insert_sql = "INSERT INTO fediverse(server, updated_at, software, users, mau, alive, users_api, version) VALUES(%s,%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
conn = None conn = None
@ -111,11 +111,11 @@ class Database():
print(f'Writing {server} nodeinfo data...') print(f'Writing {server} nodeinfo data...')
cur.execute(insert_sql, (server, now, software, users, alive, api, soft_version)) cur.execute(insert_sql, (server, now, software, users, mau, alive, api, soft_version))
cur.execute( cur.execute(
"UPDATE fediverse SET updated_at=(%s), software=(%s), users=(%s), alive=(%s), users_api=(%s), version=(%s) where server=(%s)", "UPDATE fediverse SET updated_at=(%s), software=(%s), users=(%s), mau=(%s), alive=(%s), users_api=(%s), version=(%s) where server=(%s)",
(now, software, users, alive, api, soft_version, server) (now, software, users, mau, alive, api, soft_version, server)
) )
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,)) cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))

Veure arxiu

@ -203,10 +203,10 @@ def getsoft(server):
users = nodeinfo_json.get('usage').get('users').get('total') or '0' users = nodeinfo_json.get('usage').get('users').get('total') or '0'
if users > 1000000: if users > 1000000:
return return
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
alive = True alive = True
db.write_api(server, soft, users, alive, nodeinfo, soft_version) db.write_api(server, soft, users, mau, alive, nodeinfo, soft_version)
print(f"Server {server} ({soft} {soft_version}) is alive!") print(f"Server {server} ({soft} {soft_version}) is alive!")
print('*********************************************************************') print('*********************************************************************')
@ -227,12 +227,12 @@ def getsoft(server):
users = nodeinfo_json['usage']['users']['total'] users = nodeinfo_json['usage']['users']['total']
if users > 1000000: if users > 1000000:
return return
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
alive = True alive = True
if soft == 'socialhome': if soft == 'socialhome':
db.write_api(server, soft, users, alive, nodeinfo, soft_version) db.write_api(server, soft, users, mau, alive, nodeinfo, soft_version)
print('*********************************************************************') print('*********************************************************************')
print(f"Server {serve}r ({soft} {soft_version}) is alive!") print(f"Server {serve}r ({soft} {soft_version}) is alive!")
@ -268,9 +268,10 @@ def getsoft(server):
soft_version = 'unknown' soft_version = 'unknown'
mau = 0
alive = True alive = True
db.write_api(server, soft, users, alive, nodeinfo, soft_version) db.write_api(server, soft, users, mau, alive, nodeinfo, soft_version)
print('*********************************************************************') print('*********************************************************************')
print(f"Server {server} ({soft}) is alive!") print(f"Server {server} ({soft}) is alive!")

Veure arxiu

@ -209,7 +209,7 @@ class Query():
self.alive = True self.alive = True
self.db.write_api(server, self.soft, self.users, self.alive, nodeinfo, self.soft_version) self.db.write_api(server, self.soft, self.users, self.mau, self.alive, nodeinfo, self.soft_version)
print(f"Server {server} ({self.soft} {self.soft_version}) is alive!") print(f"Server {server} ({self.soft} {self.soft_version}) is alive!")
print('*********************************************************************') print('*********************************************************************')