Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

create a tik tok username checker with library request and colorama

  1. User

    create a tik tok username checker with library request and colorama

  2. Assistant

    Sure! Here's an example of a TikTok username checker using the requests library and colorama for 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_username function 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 the requests library.

    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 colorama and use Fore to set the text color for the output messages. We can reset the color using Fore.RESET after each message.

    Finally, in the main section, we prompt the user to enter a TikTok username, call the check_tiktok_username function, and print the result.

    Remember to install the required libraries by running pip install requests colorama before executing the code.