Fixed some warnings

This commit is contained in:
spla 2021-05-14 13:14:31 +02:00
pare a935ef8029
commit 8185045292

Veure arxiu

@ -1,34 +1,18 @@
import time import time
import urllib3 import urllib3
from urllib3 import exceptions
from datetime import datetime from datetime import datetime
from subprocess import call
from mastodon import Mastodon from mastodon import Mastodon
import threading
import os import os
import json import json
import signal
import sys import sys
import os.path import os.path
import requests import requests
from requests import exceptions
import operator
import calendar
import psycopg2 import psycopg2
from itertools import product from itertools import product
from multiprocessing import Pool, Lock, Process, Queue, current_process, Manager
import multiprocessing import multiprocessing
import aiohttp import aiohttp
import aiodns
import asyncio import asyncio
from aiohttp import ClientError, ClientSession, ClientConnectionError, ClientConnectorError, ClientSSLError, ClientConnectorSSLError, ServerTimeoutError
from asyncio import TimeoutError
import socket import socket
from socket import gaierror, gethostbyname
import matplotlib
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.style.use('seaborn') plt.style.use('seaborn')
@ -50,9 +34,11 @@ client_exceptions = (
) )
def is_json(myjson): def is_json(myjson):
try: try:
json_object = json.loads(myjson) json_object = json.loads(myjson)
except ValueError as e: except ValueError as e:
print(e)
return False return False
return True return True
@ -62,10 +48,10 @@ def get_alive_servers(server):
serv_soft = '' serv_soft = ''
soft_version = '' soft_version = ''
conn = None
try: try:
conn = None
conn = psycopg2.connect(database=fediverse_db, user=fediverse_db_user, password="", host="/var/run/postgresql", port="5432") conn = psycopg2.connect(database=fediverse_db, user=fediverse_db_user, password="", host="/var/run/postgresql", port="5432")
cur = conn.cursor() cur = conn.cursor()
@ -74,7 +60,7 @@ def get_alive_servers(server):
row = cur.fetchone() row = cur.fetchone()
if row != None: if row is not None:
was_alive = row[0] was_alive = row[0]
serv_soft = row[1] serv_soft = row[1]
@ -172,7 +158,7 @@ def get_alive_servers(server):
if alive: if alive:
if soft_version != "" and soft_version != None: if soft_version is not "" and soft_version is not None:
print("Server " + str(server) + " (" + serv_soft + " " + soft_version + ") is alive!") print("Server " + str(server) + " (" + serv_soft + " " + soft_version + ") is alive!")
else: else:
print("Server " + str(server) + " (" + serv_soft + ") is alive!") print("Server " + str(server) + " (" + serv_soft + ") is alive!")
@ -207,54 +193,63 @@ def get_alive_servers(server):
except urllib3.exceptions.ProtocolError as protoerr: except urllib3.exceptions.ProtocolError as protoerr:
print(protoerr)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.ChunkedEncodingError as chunkerr: except requests.exceptions.ChunkedEncodingError as chunkerr:
print(chunkerr)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except KeyError as e: except KeyError as e:
print(e)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except ValueError as verr: except ValueError as verr:
print(verr)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.SSLError as errssl: except requests.exceptions.SSLError as errssl:
print(errssl)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.HTTPError as errh: except requests.exceptions.HTTPError as errh:
print(errh)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.ConnectionError as errc: except requests.exceptions.ConnectionError as errc:
print(errc)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.Timeout as errt: except requests.exceptions.Timeout as errt:
print(errt)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
except requests.exceptions.RequestException as err: except requests.exceptions.RequestException as err:
print(err)
print("Server " + server + " is dead :-(") print("Server " + server + " is dead :-(")
alive = False alive = False
pass pass
@ -264,7 +259,7 @@ def get_alive_servers(server):
print(gai_error) print(gai_error)
pass pass
if alive == False: if alive is False:
conn = None conn = None
@ -348,6 +343,7 @@ async def getsoft(server):
except: except:
pass pass
except aiohttp.ClientConnectorError as err: except aiohttp.ClientConnectorError as err:
print(err)
pass pass
else: else:
if response.status == 200 and api != '/api/v1/instance?': if response.status == 200 and api != '/api/v1/instance?':
@ -440,7 +436,7 @@ def get_last_checked_servers():
cur = conn.cursor() cur = conn.cursor()
### get world servers list # get world servers list
cur.execute("select server from world where server in (select server from fediverse where users_api != '')") cur.execute("select server from world where server in (select server from fediverse where users_api != '')")
@ -505,6 +501,7 @@ def usage():
# Returns the parameter from the specified file # Returns the parameter from the specified file
def get_parameter(parameter, file_path): def get_parameter(parameter, file_path):
# Check if secrets file exists # Check if secrets file exists
if not os.path.isfile(file_path): if not os.path.isfile(file_path):
print("File %s not found, exiting."%file_path) print("File %s not found, exiting."%file_path)
@ -640,7 +637,7 @@ if __name__ == '__main__':
row = cur.fetchone() row = cur.fetchone()
if row != None: if row is not None:
servers_before = row[0] servers_before = row[0]
users_before = row[1] users_before = row[1]
@ -743,7 +740,7 @@ if __name__ == '__main__':
row = cur.fetchone() row = cur.fetchone()
if row != None: if row is not None:
max_servers = row[0] max_servers = row[0]
@ -755,7 +752,7 @@ if __name__ == '__main__':
row = cur.fetchone() row = cur.fetchone()
if row != None: if row is not None:
max_users = row[0] max_users = row[0]