Skip to content

Commit dab8f73

Browse files
authored
Merge pull request #80 from Fort503/feature/stackoverflow-validator
Add StackOverflow username validator
2 parents dd3d4be + b6cbdfb commit dab8f73

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

user_scanner/community/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# community
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)

0 commit comments

Comments
 (0)