create a tik tok username checker with library request and colorama
- User
create a tik tok username checker with library request and colorama
- Assistant
Sure! Here's an example of a TikTok username checker using the
requestslibrary andcoloramafor colored output:import requests from colorama import Fore def check_tiktok_username(username): url = f"https://www.tiktok.com/@{username}" response = requests.get(url) if response.status_code == 200: return f"{Fore.RED}{username} is taken!{Fore.RESET}" elif response.status_code == 404: return f"{Fore.GREEN}{username} is available!{Fore.RESET}" else: return f"{Fore.YELLOW}Couldn't check username availability. Try again later.{Fore.RESET}" if __name__ == "__main__": # Prompt user for TikTok username input username = input("Enter TikTok username to check: ") result = check_tiktok_username(username) print(result)In this code, we define the
check_tiktok_usernamefunction which takes a TikTok username as input. It constructs the URL for the profile page of the username and sends a GET request to that URL using therequestslibrary.We then check the response status code: if it's 200, it means the username is taken. If it's 404, it means the username is available. For any other status code, we display a message indicating that the username availability couldn't be determined at the moment.
To add colored output, we import
coloramaand useForeto set the text color for the output messages. We can reset the color usingFore.RESETafter each message.Finally, in the main section, we prompt the user to enter a TikTok username, call the
check_tiktok_usernamefunction, and print the result.Remember to install the required libraries by running
pip install requests coloramabefore executing the code.