Skip to content

Commit bef86b3

Browse files
committed
mv: Move all the username validations in a different directory
1 parent 752abdc commit bef86b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1582
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# community
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from user_scanner.core.orchestrator import status_validate
2+
3+
4+
def validate_coderlegion(user):
5+
url = f"https://coderlegion.com/user/{user}"
6+
7+
return status_validate(url, 404, 200, timeout=15.0)
8+
9+
10+
if __name__ == "__main__":
11+
user = input("Username?: ").strip()
12+
result = validate_coderlegion(user)
13+
14+
if result == 1:
15+
print("Available!")
16+
elif result == 0:
17+
print("Unavailable!")
18+
else:
19+
print("Error occured!")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import re
2+
from user_scanner.core.orchestrator import generic_validate, Result
3+
4+
5+
def validate_hackernews(user: str) -> Result:
6+
if not (2 <= len(user) <= 15):
7+
return Result.error("Length must be 2-15 characters")
8+
9+
if not re.match(r'^[a-zA-Z0-9_-]+$', user):
10+
return Result.error("Only use letters, numbers, underscores, and hyphens")
11+
12+
url = f"https://news.ycombinator.com/user?id={user}"
13+
14+
def process(response):
15+
if "No such user." in response.text:
16+
return Result.available()
17+
if f"profile: {user}" in response.text.lower() or "created:" in response.text:
18+
return Result.taken()
19+
return Result.error("Unexpected response structure")
20+
21+
return generic_validate(url, process, timeout=3.0, follow_redirects=True)
22+
23+
24+
if __name__ == "__main__":
25+
user = input("Username?: ").strip()
26+
result = validate_hackernews(user)
27+
28+
if result == 1:
29+
print("Available!")
30+
elif result == 0:
31+
print("Unavailable!")
32+
else:
33+
print(f"Error occurred! Reason: {result.get_reason()}")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from user_scanner.core.orchestrator import generic_validate
2+
from user_scanner.core.result import Result
3+
4+
def validate_stackoverflow(user: str) -> Result:
5+
url = f"https://stackoverflow.com/users/filter?search={user}"
6+
7+
def process(response):
8+
if response.status_code == 200:
9+
text = response.text
10+
11+
if "No users matched your search." in text:
12+
return Result.available()
13+
14+
pattern = f'>{user}<'
15+
if pattern in text:
16+
return Result.taken()
17+
18+
return Result.available()
19+
20+
return Result.error("Unexpected status code from Stack Overflow")
21+
22+
return generic_validate(url, process)
23+
24+
25+
if __name__ == "__main__":
26+
user = input("Username?: ").strip()
27+
result = validate_stackoverflow(user)
28+
29+
if result == Result.available():
30+
print("Available!")
31+
elif result == Result.taken():
32+
print("Unavailable!")
33+
else:
34+
msg = result.get_reason()
35+
print("Error occurred!" + msg)

user_scanner/user_scan/creator/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from user_scanner.core.orchestrator import status_validate
2+
3+
4+
def validate_devto(user):
5+
url = f"https://dev.to/{user}"
6+
7+
return status_validate(url, 404, 200, follow_redirects=True)
8+
9+
10+
if __name__ == "__main__":
11+
user = input("Username?: ").strip()
12+
result = validate_devto(user)
13+
14+
if result == 1:
15+
print("Available!")
16+
elif result == 0:
17+
print("Unavailable!")
18+
else:
19+
print("Error occurred!")
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from user_scanner.core.result import Result
2+
from user_scanner.core.orchestrator import generic_validate
3+
4+
5+
def validate_hashnode(user):
6+
url = "https://hashnode.com/utility/ajax/check-username"
7+
8+
payload = {
9+
"username": user,
10+
"name": "Dummy Dummy"
11+
}
12+
13+
headers = {
14+
'User-Agent': "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36",
15+
'Accept': "application/json",
16+
'Content-Type': "application/json",
17+
'Origin': "https://hashnode.com",
18+
'Referer': "https://hashnode.com/signup",
19+
}
20+
21+
def process(response):
22+
if response.status_code == 200:
23+
data = response.json()
24+
25+
if 'status' in data:
26+
if data['status'] == 1:
27+
return Result.available()
28+
elif data['status'] == 0:
29+
return Result.taken()
30+
31+
return Result.error("Status not found")
32+
33+
else:
34+
return Result.error("Invalid status code")
35+
36+
return generic_validate(url, process, method="POST", json=payload, headers=headers, timeout=3.0)
37+
38+
if __name__ == "__main__":
39+
user = input("Username?: ").strip()
40+
result = validate_hashnode(user)
41+
42+
if result == 1:
43+
print("Available!")
44+
elif result == 0:
45+
print("Unavailable!")
46+
else:
47+
print("Error occurred!")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import re
2+
from user_scanner.core.orchestrator import status_validate, Result
3+
4+
5+
def validate_itch_io(user: str) -> Result:
6+
if not (2 <= len(user) <= 25):
7+
return Result.error("Length must be 2-25 characters.")
8+
9+
if not re.match(r'^[a-z0-9_-]+$', user):
10+
11+
if re.search(r'[A-Z]', user):
12+
return Result.error("Use lowercase letters only.")
13+
14+
return Result.error("Only use lowercase letters, numbers, underscores, and hyphens.")
15+
16+
url = f"https://itch.io/profile/{user}"
17+
18+
return status_validate(url, 404, 200, follow_redirects=True)
19+
20+
21+
if __name__ == "__main__":
22+
user = input("Username?: ").strip()
23+
result = validate_itch_io(user)
24+
25+
if result == 1:
26+
print("Available!")
27+
elif result == 0:
28+
print("Unavailable!")
29+
else:
30+
print(f"Error occurred! Reason: {result.get_reason()}")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from user_scanner.core.orchestrator import status_validate
2+
3+
4+
def validate_kaggle(user):
5+
url = f"https://www.kaggle.com/{user}"
6+
7+
return status_validate(url, 404, 200, follow_redirects=True)
8+
9+
10+
if __name__ == "__main__":
11+
user = input("Username?: ").strip()
12+
result = validate_kaggle(user)
13+
14+
if result == 1:
15+
print("Available!")
16+
elif result == 0:
17+
print("Unavailable!")
18+
else:
19+
print("Error occurred!")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from user_scanner.core.orchestrator import generic_validate
2+
from user_scanner.core.result import Result
3+
4+
5+
def validate_medium(user):
6+
url = f"https://medium.com/@{user}"
7+
8+
headers = {
9+
'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
10+
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
11+
'Accept-Encoding': "identity",
12+
'upgrade-insecure-requests': "1",
13+
'sec-fetch-site': "none",
14+
'sec-fetch-mode': "navigate",
15+
'sec-fetch-user': "?1",
16+
'sec-fetch-dest': "document",
17+
'sec-ch-ua': "\"Google Chrome\";v=\"143\", \"Chromium\";v=\"143\", \"Not A(Brand\";v=\"24\"",
18+
'sec-ch-ua-mobile': "?0",
19+
'sec-ch-ua-platform': "\"Linux\"",
20+
'accept-language': "en-US,en;q=0.9",
21+
'priority': "u=0, i"
22+
}
23+
24+
def process(response):
25+
if response.status_code == 200:
26+
html_text = response.text
27+
28+
username_tag = f'property="profile:username" content="{user}"'
29+
30+
if username_tag in html_text:
31+
return Result.taken()
32+
else:
33+
return Result.available()
34+
return Result.error()
35+
36+
return generic_validate(url, process, headers=headers)
37+
38+
39+
if __name__ == "__main__":
40+
user = input("Username?: ").strip()
41+
result = validate_medium(user)
42+
43+
if result == 1:
44+
print("Available!")
45+
elif result == 0:
46+
print("Unavailable!")
47+
else:
48+
print(f"Error occurred! Reason: {result.get_reason()}")

0 commit comments

Comments
 (0)