Added Best Fediverse Server Uptime Publishing Bot
This commit is contained in:
pare
cf6cc29a15
commit
1bf67f2f28
S'han modificat 1 arxius amb 22 adicions i 6 eliminacions
28
fediverse.py
28
fediverse.py
|
@ -53,7 +53,7 @@ def get_alive_servers(server):
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("select alive, software, users_api, version from fediverse where server=(%s)", (server,))
|
||||
cur.execute("select alive, software, users_api, version, first_checked_at from fediverse where server=(%s)", (server,))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
|
@ -63,6 +63,7 @@ def get_alive_servers(server):
|
|||
serv_soft = row[1]
|
||||
serv_api = row[2]
|
||||
soft_version = row[3]
|
||||
first_checked_at = row[4]
|
||||
|
||||
cur.close()
|
||||
|
||||
|
@ -79,7 +80,9 @@ def get_alive_servers(server):
|
|||
|
||||
try:
|
||||
|
||||
data = requests.get('https://' + server + serv_api, timeout=3)
|
||||
user_agent = {'User-agent': 'Mozilla/5.0'}
|
||||
|
||||
data = requests.get('https://' + server + serv_api, headers = user_agent, timeout=3)
|
||||
|
||||
if serv_soft == "mastodon":
|
||||
if serv_api == '/nodeinfo/2.0?':
|
||||
|
@ -160,7 +163,7 @@ def get_alive_servers(server):
|
|||
else:
|
||||
print("Server " + str(server) + " (" + serv_soft + ") is alive!")
|
||||
|
||||
insert_sql = "INSERT INTO fediverse(server, users, updated_at, software, alive, users_api, version) VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
insert_sql = "INSERT INTO fediverse(server, users, updated_at, software, alive, users_api, version, first_checked_at, last_checked_at) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
|
||||
conn = None
|
||||
|
||||
|
@ -170,9 +173,16 @@ def get_alive_servers(server):
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(insert_sql, (server, users, now, serv_soft, alive, serv_api, soft_version))
|
||||
cur.execute(insert_sql, (server, users, now, serv_soft, alive, serv_api, soft_version, now, now))
|
||||
|
||||
if first_checked_at != None:
|
||||
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), last_checked_at=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, server))
|
||||
|
||||
else:
|
||||
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), first_checked_at=(%s), last_checked_at=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, now, server))
|
||||
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, server))
|
||||
|
||||
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))
|
||||
|
||||
|
@ -267,7 +277,13 @@ def get_alive_servers(server):
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s) where server=(%s)", (now, alive, server))
|
||||
if first_checked_at != None:
|
||||
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s), first_checked_at=(%s) where server=(%s)", (now, alive, NULL, server))
|
||||
|
||||
else:
|
||||
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s) where server=(%s)", (now, alive, server))
|
||||
|
||||
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))
|
||||
|
||||
|
|
Loading…
Referencia en una nova incidència