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