from sys import argv import psycopg2 def get_connection(): db_connect = psycopg2.connect(host="localhost", database="postgres", user="postgres", password="postgres") db_connect.set_session(autocommit=True) return db_connect def is_admin(username: str) -> bool: conn = get_connection() with conn.cursor() as cursor: cursor.execute("""SELECT is_admin FROM users WHERE username = '%s' """ % username) result = cursor.fetchone() # fetchone gibt NONE zurück, falls kein Benutzer gefunden wird if result is None: return False admin, = result return admin if __name__ == "__main__": username = str(argv[1]) print(username + " is an admin: " + str(is_admin(username)))