first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:26:46 +03:00
commit 2be3a313ad
55 changed files with 3609 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import re
def normalize_for_username(value):
"""Turkce karakterleri ASCII'ye cevirip username-safe hale getirir."""
tr_map = str.maketrans({
'c': 'c',
'C': 'c',
'g': 'g',
'G': 'g',
'i': 'i',
'I': 'i',
'o': 'o',
'O': 'o',
's': 's',
'S': 's',
'u': 'u',
'U': 'u',
'ç': 'c',
'Ç': 'c',
'ğ': 'g',
'Ğ': 'g',
'ı': 'i',
'İ': 'i',
'ö': 'o',
'Ö': 'o',
'ş': 's',
'Ş': 's',
'ü': 'u',
'Ü': 'u',
})
value = value.translate(tr_map).lower()
return re.sub(r'[^a-z0-9]+', '', value)
def build_unique_username(first_name, last_name, birth_date, used_usernames, _force_suffix=None):
"""
ad.soyadYY formatinda username uretir, cakisma olursa sonek ekler.
_force_suffix: verilirse bare base denenmez, bu sayidan itibaren baslar
(regeneration ping-pong onlemek icin kullanilir).
"""
first = normalize_for_username(first_name or '')
last = normalize_for_username(last_name or '')
yy = str(birth_date.year)[-2:]
base = f"{first}.{last}{yy}" if first and last else f"user{yy}"
if _force_suffix is not None:
# Yeniden uretim: bare base'i hic deneme, rastgele bir sonek ile basla
counter = _force_suffix
candidate = f"{base}{counter}"
else:
candidate = base
counter = 1
while candidate in used_usernames:
counter += 1
candidate = f"{base}{counter}"
used_usernames.add(candidate)
return candidate