GXHub

GXHub is a command-line tool that retrieves and displays GitHub user information.

1. print_banner()


def print_banner():
    banner = '''
    ██████  ██     ██ ██   ██ ██    ██ ██████  
    ██        ██  ██  ██   ██ ██    ██ ██   ██ 
    ██   ███   ███    ███████ ██    ██ ██████  
    ██    ██  ██  ██  ██   ██ ██    ██ ██   ██ 
    ██████  ██     ██ ██   ██  ██████  ██████  
    '''
    print(textwrap.dedent(banner))
            

Summary: This function prints the GXHub banner when the script is executed, providing a visual identity to the tool.

GitHub User Info Output

2. get_user_info(username)


def get_user_info(username):
    try:
        user_api_url = f"https://api.github.com/users/{username}"
        response = requests.get(user_api_url, timeout=10)
        response.raise_for_status()
        user_data = response.json()
        user_info = {
            "Login": user_data.get("login"),
            "ID": user_data.get("id"),
            "Avatar URL": user_data.get("avatar_url"),
            "Profile URL": user_data.get("html_url"),
            "Type": user_data.get("type"),
            "Created": user_data.get("created_at"),
            "Last Updated": user_data.get("updated_at"),
        }
        display_table(user_info, title="GitHub User Info")
        return user_info
    except Exception as e:
        print(f"Error retrieving user info: {str(e)}")
        return None
            

Summary: This function fetches the user profile data from GitHub and displays it in a structured table format. It includes details such as the login name, profile URL, creation date, etc.

GitHub User Info Output

3. get_github_events(username)


def get_github_events(username):
    try:
        github_api_url = f"https://api.github.com/users/{username}/events/public"
        response = requests.get(github_api_url, timeout=10)
        response.raise_for_status()
        github_data = response.json()
        email_addresses = set()
        for event in github_data:
            if event['type'] == 'PushEvent':
                for commit in event['payload']['commits']:
                    email_addresses.add(commit['author']['email'])
        display_table(email_addresses, title="Email Addresses Found in Commits")
        return email_addresses
    except Exception as e:
        print(f"Error retrieving events: {str(e)}")
        return None
            

Summary: This function retrieves public events associated with a user and extracts email addresses found in PushEvent commits. It displays the emails in a table.

Email Addresses Found in Commits

4. get_user_repositories(username)


def get_user_repositories(username):
    try:
        api_url = f"https://api.github.com/users/{username}/repos"
        response = requests.get(api_url, timeout=10)
        response.raise_for_status()
        repos = response.json()
        repo_data = []
        for repo in repos:
            repo_data.append({
                "Name": repo.get("name", "N/A"),
                "Description": repo.get("description", "N/A") or "No description",
                "Language": repo.get("language", "N/A"),
                "Stars": repo.get("stargazers_count", 0),
                "Last Updated": repo.get("updated_at", "N/A"),
            })
        display_table(repo_data, title="User Repositories")
        return repo_data
    except Exception as e:
        print(f"Error retrieving repositories: {str(e)}")
        return []
            

Summary: This function fetches the user’s public repositories from GitHub, displaying information such as name, description, language, stars, and last updated time.

Public Repositories Output

5. Text File Output


if __name__ == "__main__":
    print_banner()
    if len(sys.argv) != 2:
        print("Usage: python gxhub.py ")
        sys.exit(1)
    username = sys.argv[1]
    user_info = get_user_info(username)
    email_info = get_github_events(username)
    repo_info = get_user_repositories(username)
    if user_info or email_info or repo_info:
        with open(f"{username}.txt", "w") as file:
            file.write("GitHub User Info:\n")
            if user_info:
                for key, value in user_info.items():
                    file.write(f"{key}: {value}\n")
            file.write("\nEmail Addresses Found:\n")
            if email_info:
                for email in email_info:
                    file.write(f"{email}\n")
            file.write("\nPublic Repositories:\n")
            if repo_info:
                for repo in repo_info:
                    file.write(f"\nRepository Name: {repo['Name']}\n")
                    file.write(f"Description: {repo['Description']}\n")
                    file.write(f"Language: {repo['Language']}\n")
                    file.write(f"Stars: {repo['Stars']}\n")
                    file.write(f"Last Updated: {repo['Last Updated']}\n")
            else:
                file.write("No repositories found.\n")
            print(f"\nThe information has been saved to {username}.txt")
            

Summary: This block of code saves all the gathered data into a text file named after the GitHub username. The file contains user info, email addresses, and repository details.

Text File Output