Removed unneeded methods

This commit is contained in:
spla 2023-04-13 18:10:58 +02:00
pare c535f37a99
commit 97a8298e65
S'han modificat 2 arxius amb 4 adicions i 394 eliminacions

Veure arxiu

@ -25,54 +25,14 @@ class Database():
if not db_setup: if not db_setup:
self.blocker_db = input("\nMau database name: ") self.blocker_db = input("\nblocksoft database name: ")
self.blocker_db_user = input("\nMau database user: ") self.blocker_db_user = input("\nblocksoft database user: ")
self.blocker_db_user_password = input("\nMau database user password: ") self.blocker_db_user_password = input("\nblocksoft database user password: ")
self.__createdb(self) self.__createdb(self)
self.__create_config(self) self.__create_config(self)
self.__write_config(self) self.__write_config(self)
def get_nodeinfo_endpoint(self, server):
try:
conn = None
conn = psycopg2.connect(database = self.blocker_db, user = self.blocker_db_user, password = self.blocker_db_user_password, host = "/var/run/postgresql", port = "6432")
cur = conn.cursor()
cur.execute("select server, api from servers where server=(%s)", (server,))
row = cur.fetchone()
if row != None:
server = row[0]
api = row[1]
else:
server = ''
api = ''
cur.close()
return (server, api)
except (Exception, psycopg2.DatabaseError) as error:
sys.exit(error)
finally:
if conn is not None:
conn.close()
def get_servers(self, software): def get_servers(self, software):
servers_list = [] servers_list = []
@ -107,356 +67,6 @@ class Database():
return (servers_list) return (servers_list)
def save_time(self, program, start, finish):
insert_sql = "INSERT INTO execution_time(program, start, finish) VALUES(%s,%s,%s) ON CONFLICT DO NOTHING"
conn = None
try:
conn = psycopg2.connect(database = self.blocker_db, user = self.blocker_db_user, password = self.blocker_db_user_password, host = "/var/run/postgresql", port = "6432")
cur = conn.cursor()
cur.execute(insert_sql, (program, start, finish,))
cur.execute("UPDATE execution_time SET start=(%s), finish=(%s) where program=(%s)", (start, finish, program))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
def check_peer(self, server):
found = False
select_server_sql = 'select server from servers where server=(%s)'
select_dead_server_sql = 'select server from deadservers where server=(%s)'
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
# check server
cur.execute(select_server_sql, (server,))
row = cur.fetchone()
if row != None:
found = True
cur.execute(select_dead_server_sql, (server,))
row = cur.fetchone()
if row != None:
found = True
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return found
def get_not_updated_servers(self):
not_updated_servers = []
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
# get saved servers list
cur.execute("select server from servers where updated_at is null")
rows = cur.fetchall()
for row in rows:
not_updated_servers.append(row[0])
cur.close()
print("Not updated servers: " + str(len(not_updated_servers)))
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return not_updated_servers
def get_saved_servers(self):
saved_servers = []
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
# get saved servers list
cur.execute("select server from servers where api is not null")
rows = cur.fetchall()
for row in rows:
saved_servers.append(row[0])
cur.close()
print("Saved servers: " + str(len(saved_servers)))
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return saved_servers
def get_dead_servers(self):
dead_servers = []
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
# get dead servers list
cur.execute("select server from deadservers")
rows = cur.fetchall()
for row in rows:
dead_servers.append(row[0])
cur.close()
print("Dead servers: " + str(len(dead_servers)))
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return dead_servers
def soft_totals(self):
# get current total servers and users, get users from every software
now = datetime.now()
gettotals_sql = "select count(server), sum(users), sum(mau) from mau where alive"
get_soft_totals_sql = "select software, sum(users) as users, sum(mau) as mau, count(server) as servers from mau where users != 0 and mau is not null and alive group by software order by mau desc"
soft_total_project = []
soft_total_users = []
soft_total_mau = []
soft_total_servers = []
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
cur.execute(gettotals_sql)
row = cur.fetchone()
total_servers = row[0]
total_users = row[1]
total_mau = row[2]
cur.execute(get_soft_totals_sql)
rows = cur.fetchall()
for row in rows:
soft_total_project.append(row[0])
soft_total_users.append(row[1])
soft_total_mau.append(row[2])
soft_total_servers.append(row[3])
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return (soft_total_project, soft_total_users, soft_total_mau, soft_total_servers, total_servers, total_users, total_mau)
def get_last_checked_servers(self):
# get last checked servers from fediverse DB
alive_servers = []
try:
conn = None
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
# get world servers list
cur.execute("select server from world where server in (select server from fediverse where users_api != '')")
rows = cur.fetchall()
for row in rows:
alive_servers.append(row[0])
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
return alive_servers
def write_alive_server(self, server, software, version, users, mau, alive):
now = datetime.now()
insert_sql = "INSERT INTO mau(server, software, version, users, mau, alive, updated_at) VALUES(%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
conn = None
try:
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
cur.execute(insert_sql, (server, software, version, users, mau, alive, now))
cur.execute("UPDATE mau SET software=(%s), version=(%s), users=(%s), mau=(%s), alive=(%s), updated_at=(%s) where server=(%s)", (software, version, users, mau, alive, now, server))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
def write_not_alive_server(self, server):
now = datetime.now()
update_sql = "UPDATE mau set alive='f', updated_at=(%s) where server=(%s)"
conn = None
try:
conn = psycopg2.connect(database=self.blocker_db, user=self.blocker_db_user, password = self.blocker_db_user_password, host="/var/run/postgresql", port="6432")
cur = conn.cursor()
cur.execute(update_sql, (now, server))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
def write_server(self, server, api, software): def write_server(self, server, api, software):
now = datetime.now() now = datetime.now()

Veure arxiu

@ -49,7 +49,7 @@ class Setup():
self.mastodon_user = input("Mastodon user login? ") self.mastodon_user = input("Mastodon user login? ")
self.mastodon_password = input("Mastodon user password? ") self.mastodon_password = input("Mastodon user password? ")
self.app_name = 'fediverse' self.app_name = 'blocksoft'
self.mastodon_app_token = self.mastodon_log_in() self.mastodon_app_token = self.mastodon_log_in()