-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhychecker.py
More file actions
114 lines (92 loc) · 3.78 KB
/
hychecker.py
File metadata and controls
114 lines (92 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import requests
import time
import os
import sys
import re
API_URL = "https://api.hytl.tools/check/{}"
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
FILE_PATH = os.path.join(SCRIPT_DIR, "name.txt")
if len(sys.argv) > 1:
FILE_PATH = sys.argv[1]
OUTPUT_FILE = os.path.join(SCRIPT_DIR, "name_checked.txt")
AVAILABLE_FILE = os.path.join(SCRIPT_DIR, "available_names.txt")
UNAVAILABLE_FILE = os.path.join(SCRIPT_DIR, "unavailable_names.txt")
def normalize_name(name):
"""Normalize username: lowercase, remove spaces/dashes, keep only a-z, 0-9, underscore."""
name = name.replace(" ", "").replace("-", "").lower()
name = re.sub(r"[^a-z0-9_]", "", name)
return name
def check_name(name):
"""Check availability of a username via the API."""
try:
response = requests.get(API_URL.format(name.strip()), timeout=5)
if response.status_code == 200:
data = response.json()
if data.get("available"):
return "✔️"
else:
return "❌"
else:
return f"error {response.status_code}"
except requests.exceptions.RequestException as e:
return f"error {e}"
def load_existing(file_path):
"""Load existing usernames from a file into a set."""
if os.path.exists(file_path):
with open(file_path, "r", encoding="utf-8") as f:
return set(line.strip().split(" (")[0] for line in f if line.strip())
return set()
def main():
if not os.path.exists(FILE_PATH):
print(f"File not found: {FILE_PATH}")
return
skipped = []
new_lines = []
with open(FILE_PATH, "r", encoding="utf-8") as f:
for line in f:
raw_name = line.strip()
if not raw_name:
continue
name = normalize_name(raw_name)
if len(name) < 3 or len(name) > 16:
skipped.append(raw_name)
continue
new_lines.append(name)
if skipped:
print(f"⚠ Skipped {len(skipped)} usernames (too short, too long, or invalid chars): {', '.join(skipped)}")
if not new_lines:
print("⚠ No valid usernames to check (3–16 characters, letters/numbers/underscore only).")
return
checked_names = load_existing(OUTPUT_FILE)
available_names_existing = load_existing(AVAILABLE_FILE)
unavailable_names_existing = load_existing(UNAVAILABLE_FILE)
output_lines = []
available_names = set(available_names_existing)
unavailable_names = set(unavailable_names_existing)
print(f"\n🔎 Checking {len(new_lines)} new usernames...\n")
for idx, line in enumerate(new_lines, start=1):
if line in checked_names:
print(f"{idx}/{len(new_lines)}: {line} → already checked")
continue
status = check_name(line)
output_lines.append(f"{line} ({status})")
if status == "✔️":
available_names.add(line)
elif status == "❌":
unavailable_names.add(line)
print(f"{idx}/{len(new_lines)}: {line} → {status}")
time.sleep(0.25)
if output_lines:
with open(OUTPUT_FILE, "a", encoding="utf-8") as f:
f.write("\n".join(output_lines) + "\n")
with open(AVAILABLE_FILE, "w", encoding="utf-8") as f:
f.write("\n".join(sorted(available_names)) + "\n")
with open(UNAVAILABLE_FILE, "w", encoding="utf-8") as f:
f.write("\n".join(sorted(unavailable_names)) + "\n")
print(f"\n💠 [DONE]")
print(f"\n> Updated files:")
print(f"- {OUTPUT_FILE} (Full List)")
print(f"- {AVAILABLE_FILE} (Available)")
print(f"- {UNAVAILABLE_FILE} (Unavailable)")
if __name__ == "__main__":
main()