Initial commit
Dieser Commit ist enthalten in:
89
social_networks/vk/vk_utils.py
Normale Datei
89
social_networks/vk/vk_utils.py
Normale Datei
@ -0,0 +1,89 @@
|
||||
"""
|
||||
VK Utils - Utility-Funktionen für VK
|
||||
"""
|
||||
|
||||
import logging
|
||||
import random
|
||||
import string
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger("vk_utils")
|
||||
|
||||
class VKUtils:
|
||||
"""
|
||||
Utility-Funktionen für VK
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def generate_vk_username(first_name: str, last_name: str) -> str:
|
||||
"""
|
||||
Generiert einen VK-kompatiblen Benutzernamen
|
||||
"""
|
||||
# VK verwendet normalerweise id123456789 Format
|
||||
# Aber für die URL kann man einen benutzerdefinierten Namen verwenden
|
||||
base = f"{first_name.lower()}{last_name.lower()}"
|
||||
# Entferne Sonderzeichen
|
||||
base = ''.join(c for c in base if c.isalnum())
|
||||
|
||||
# Füge zufällige Zahlen hinzu
|
||||
random_suffix = ''.join(random.choices(string.digits, k=random.randint(2, 4)))
|
||||
|
||||
return f"{base}{random_suffix}"
|
||||
|
||||
@staticmethod
|
||||
def format_phone_number(phone: str, country_code: str = "+7") -> str:
|
||||
"""
|
||||
Formatiert eine Telefonnummer für VK
|
||||
VK ist primär in Russland, daher Standard +7
|
||||
"""
|
||||
# Entferne alle nicht-numerischen Zeichen
|
||||
phone_digits = ''.join(c for c in phone if c.isdigit())
|
||||
|
||||
# Wenn die Nummer bereits mit Ländercode beginnt
|
||||
if phone.startswith("+"):
|
||||
return phone
|
||||
|
||||
# Füge Ländercode hinzu
|
||||
return f"{country_code}{phone_digits}"
|
||||
|
||||
@staticmethod
|
||||
def is_valid_vk_password(password: str) -> bool:
|
||||
"""
|
||||
Prüft ob ein Passwort den VK-Anforderungen entspricht
|
||||
- Mindestens 6 Zeichen
|
||||
- Enthält Buchstaben und Zahlen
|
||||
"""
|
||||
if len(password) < 6:
|
||||
return False
|
||||
|
||||
has_letter = any(c.isalpha() for c in password)
|
||||
has_digit = any(c.isdigit() for c in password)
|
||||
|
||||
return has_letter and has_digit
|
||||
|
||||
@staticmethod
|
||||
def generate_vk_password(length: int = 12) -> str:
|
||||
"""
|
||||
Generiert ein VK-kompatibles Passwort
|
||||
"""
|
||||
# Stelle sicher dass Buchstaben und Zahlen enthalten sind
|
||||
password_chars = []
|
||||
|
||||
# Mindestens 2 Kleinbuchstaben
|
||||
password_chars.extend(random.choices(string.ascii_lowercase, k=2))
|
||||
|
||||
# Mindestens 2 Großbuchstaben
|
||||
password_chars.extend(random.choices(string.ascii_uppercase, k=2))
|
||||
|
||||
# Mindestens 2 Zahlen
|
||||
password_chars.extend(random.choices(string.digits, k=2))
|
||||
|
||||
# Fülle mit zufälligen Zeichen auf
|
||||
remaining_length = length - len(password_chars)
|
||||
all_chars = string.ascii_letters + string.digits
|
||||
password_chars.extend(random.choices(all_chars, k=remaining_length))
|
||||
|
||||
# Mische die Zeichen
|
||||
random.shuffle(password_chars)
|
||||
|
||||
return ''.join(password_chars)
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren