Save MAU to database
This commit is contained in:
pare
5c439bdf86
commit
60da5d7a88
S'han modificat 4 arxius amb 14 adicions i 12 eliminacions
|
@ -31,4 +31,5 @@ Within Python Virtual Environment:
|
|||
4.1.2023 - Refactored.
|
||||
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.
|
||||
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.
|
||||
|
|
10
database.py
10
database.py
|
@ -95,11 +95,11 @@ class Database():
|
|||
|
||||
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()
|
||||
|
||||
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
|
||||
|
||||
|
@ -111,11 +111,11 @@ class Database():
|
|||
|
||||
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(
|
||||
"UPDATE fediverse SET updated_at=(%s), software=(%s), users=(%s), alive=(%s), users_api=(%s), version=(%s) where server=(%s)",
|
||||
(now, software, users, alive, api, soft_version, server)
|
||||
"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, mau, alive, api, soft_version, server)
|
||||
)
|
||||
|
||||
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))
|
||||
|
|
|
@ -203,10 +203,10 @@ def getsoft(server):
|
|||
users = nodeinfo_json.get('usage').get('users').get('total') or '0'
|
||||
if users > 1000000:
|
||||
return
|
||||
|
||||
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
||||
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('*********************************************************************')
|
||||
|
@ -227,12 +227,12 @@ def getsoft(server):
|
|||
users = nodeinfo_json['usage']['users']['total']
|
||||
if users > 1000000:
|
||||
return
|
||||
|
||||
self.mau = nodeinfo_json.get('usage').get('users').get('activeMonth') or 0
|
||||
alive = True
|
||||
|
||||
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(f"Server {serve}r ({soft} {soft_version}) is alive!")
|
||||
|
@ -268,9 +268,10 @@ def getsoft(server):
|
|||
|
||||
soft_version = 'unknown'
|
||||
|
||||
mau = 0
|
||||
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(f"Server {server} ({soft}) is alive!")
|
||||
|
|
2
query.py
2
query.py
|
@ -209,7 +209,7 @@ class Query():
|
|||
|
||||
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('*********************************************************************')
|
||||
|
|
Loading…
Referencia en una nova incidència