fediverse/scripts/uptime.py

45 líneas
1,3 KiB
Python
Original Vista normal Històric

import time
import os
from datetime import datetime, timedelta
2021-08-22 12:46:43 +02:00
import humanfriendly
from setup import Setup
from database import Database
from mastodon import Mastodon
# main
if __name__ == '__main__':
setup = Setup()
mastodon = Mastodon(
access_token = setup.mastodon_app_token,
api_base_url= setup.mastodon_hostname
)
db = Database()
alive_servers, max_uptime, best_servers, software_lst, servers_lst = db.get_uptime()
toot_text = '\nAlive servers: ' + str(alive_servers)
toot_text += '\n\n'
toot_text += f"Best #fediverse's server uptime:\n{humanfriendly.format_timespan(max_uptime)}"
toot_text += '\n'
toot_text += f'\nBest uptime servers:\n{str(best_servers)} ({str(round((best_servers*100)/alive_servers,2))}%)'
toot_text += '\n\n'
toot_text += 'Best uptime softwares & servers:\n'
i = 0
while i < len(software_lst):
soft_percent = db.get_percentage(servers_lst[i], software_lst[i])
2021-08-22 12:46:43 +02:00
toot_text += ':' + str(software_lst[i]) + ': ' + str(servers_lst[i]) + ' (' + str(soft_percent) + '%)\n'
2022-03-07 19:18:34 +01:00
if len(toot_text) > 470:
break
i +=1
print("Tooting...")
print(toot_text)
mastodon.status_post(toot_text, in_reply_to_id=None)