search multi user
This commit is contained in:
		
							
								
								
									
										72
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										72
									
								
								app.py
									
									
									
									
									
								
							@@ -108,8 +108,10 @@ def get_users(db_config):
 | 
			
		||||
    connection.close()
 | 
			
		||||
    return users
 | 
			
		||||
 | 
			
		||||
def search_user(db_config, username):
 | 
			
		||||
    """Wyszukuje użytkownika po nazwie i wyświetla jego statystyki."""
 | 
			
		||||
def search_user(db_config, usernames):
 | 
			
		||||
    """Wyszukuje wielu użytkowników po nazwach i wyświetla ich statystyki w tabeli."""
 | 
			
		||||
    usernames_list = [name.strip() for name in usernames.split(',')]
 | 
			
		||||
    
 | 
			
		||||
    connection = mysql.connector.connect(**db_config)
 | 
			
		||||
    cursor = connection.cursor(dictionary=True)
 | 
			
		||||
    
 | 
			
		||||
@@ -127,19 +129,36 @@ def search_user(db_config, username):
 | 
			
		||||
    FROM users u
 | 
			
		||||
    LEFT JOIN node n ON u.uid = n.uid
 | 
			
		||||
    LEFT JOIN userpoints p ON u.uid = p.uid
 | 
			
		||||
    WHERE u.name = %s
 | 
			
		||||
    WHERE u.name IN (%s)
 | 
			
		||||
    GROUP BY u.uid
 | 
			
		||||
    """
 | 
			
		||||
    
 | 
			
		||||
    cursor.execute(query, (username,))
 | 
			
		||||
    user = cursor.fetchone()
 | 
			
		||||
    # Przygotowanie parametrów dla IN w zapytaniu SQL
 | 
			
		||||
    params = tuple(usernames_list)
 | 
			
		||||
    query = query % (','.join(['%s'] * len(usernames_list)))
 | 
			
		||||
    
 | 
			
		||||
    cursor.execute(query, params)
 | 
			
		||||
    users = cursor.fetchall()
 | 
			
		||||
    cursor.close()
 | 
			
		||||
    connection.close()
 | 
			
		||||
    
 | 
			
		||||
    if not user:
 | 
			
		||||
        print(f"❌ Użytkownik '{username}' nie został znaleziony.")
 | 
			
		||||
    if not users:
 | 
			
		||||
        print(f"❌ Żaden z użytkowników ({usernames}) nie został znaleziony.")
 | 
			
		||||
        return None
 | 
			
		||||
    
 | 
			
		||||
    # Przygotowanie danych do wyświetlenia
 | 
			
		||||
    headers = [
 | 
			
		||||
        "UID", "Nazwa użytkownika", "E-mail", "Status konta",
 | 
			
		||||
        "Data rejestracji", "Ostatnie logowanie", "Ostatnia aktywność",
 | 
			
		||||
        "Dni nieaktywności", "Punkty", "Liczba postów",
 | 
			
		||||
        "E-mail poprawny", "Tymczasowy e-mail", "Podejrzana nazwa"
 | 
			
		||||
    ]
 | 
			
		||||
    
 | 
			
		||||
    # Transpozycja danych - każdy użytkownik jako kolumna
 | 
			
		||||
    table_data = []
 | 
			
		||||
    for header in headers:
 | 
			
		||||
        row = [header]
 | 
			
		||||
        for user in users:
 | 
			
		||||
            # Dodatkowe informacje o e-mailu
 | 
			
		||||
            temp_domains_cache = load_temp_domains()
 | 
			
		||||
            email_valid = not is_fake_email(user['mail']) and not is_temp_email(user['mail'], temp_domains_cache)
 | 
			
		||||
@@ -150,28 +169,31 @@ def search_user(db_config, username):
 | 
			
		||||
            last_access = user['access'] or 0
 | 
			
		||||
            days_inactive = (now_ts - last_access) / 86400 if last_access else float('inf')
 | 
			
		||||
            
 | 
			
		||||
    # Przygotuj dane do wyświetlenia
 | 
			
		||||
            # Mapowanie danych
 | 
			
		||||
            user_data = {
 | 
			
		||||
        'UID': user['uid'],
 | 
			
		||||
        'Nazwa użytkownika': user['name'],
 | 
			
		||||
        'E-mail': user['mail'],
 | 
			
		||||
        'Status konta': 'Aktywny' if user['status'] == 1 else 'Zablokowany',
 | 
			
		||||
        'Data rejestracji': datetime.fromtimestamp(user['created']).strftime('%Y-%m-%d %H:%M:%S') if user.get('created') else 'Nieznana',
 | 
			
		||||
        'Ostatnie logowanie': datetime.fromtimestamp(user['access']).strftime('%Y-%m-%d %H:%M:%S') if user.get('access') else 'Nigdy',
 | 
			
		||||
        'Ostatnia aktywność': datetime.fromtimestamp(user['login']).strftime('%Y-%m-%d %H:%M:%S') if user.get('login') else 'Nigdy',
 | 
			
		||||
        'Dni nieaktywności': f"{days_inactive:.1f} dni",
 | 
			
		||||
        'Punkty': user.get('points', 0),
 | 
			
		||||
        'Liczba postów': user.get('post_count', 0),
 | 
			
		||||
        'E-mail poprawny': 'Tak' if email_valid else 'Nie',
 | 
			
		||||
        'Tymczasowy e-mail': 'Tak' if is_temp_email(user['mail'], temp_domains_cache) else 'Nie',
 | 
			
		||||
        'Podejrzana nazwa': 'Tak' if bad_name else 'Nie'
 | 
			
		||||
                "UID": user['uid'],
 | 
			
		||||
                "Nazwa użytkownika": user['name'],
 | 
			
		||||
                "E-mail": user['mail'],
 | 
			
		||||
                "Status konta": 'Aktywny' if user['status'] == 1 else 'Zablokowany',
 | 
			
		||||
                "Data rejestracji": datetime.fromtimestamp(user['created']).strftime('%Y-%m-%d %H:%M:%S') if user.get('created') else 'Nieznana',
 | 
			
		||||
                "Ostatnie logowanie": datetime.fromtimestamp(user['access']).strftime('%Y-%m-%d %H:%M:%S') if user.get('access') else 'Nigdy',
 | 
			
		||||
                "Ostatnia aktywność": datetime.fromtimestamp(user['login']).strftime('%Y-%m-%d %H:%M:%S') if user.get('login') else 'Nigdy',
 | 
			
		||||
                "Dni nieaktywności": f"{days_inactive:.1f} dni",
 | 
			
		||||
                "Punkty": user.get('points', 0),
 | 
			
		||||
                "Liczba postów": user.get('post_count', 0),
 | 
			
		||||
                "E-mail poprawny": 'Tak' if email_valid else 'Nie',
 | 
			
		||||
                "Tymczasowy e-mail": 'Tak' if is_temp_email(user['mail'], temp_domains_cache) else 'Nie',
 | 
			
		||||
                "Podejrzana nazwa": 'Tak' if bad_name else 'Nie'
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
    # Wyświetl wyniki w tabeli
 | 
			
		||||
    print("\n🔍 Szczegóły użytkownika:")
 | 
			
		||||
    print(tabulate([(k, v) for k, v in user_data.items()], tablefmt="fancy_grid"))
 | 
			
		||||
            row.append(user_data.get(header, ''))
 | 
			
		||||
        table_data.append(row)
 | 
			
		||||
    
 | 
			
		||||
    return user
 | 
			
		||||
    # Wyświetl wyniki w tabeli
 | 
			
		||||
    print("\n🔍 Porównanie użytkowników:")
 | 
			
		||||
    print(tabulate(table_data, headers=[""] + [user['name'] for user in users], tablefmt="fancy_grid"))
 | 
			
		||||
    
 | 
			
		||||
    return users
 | 
			
		||||
 | 
			
		||||
def is_fake_email(email):
 | 
			
		||||
    try:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user