|
| 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