Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- """Github User Info
- Get basic information on a Github user
- Usage:
- github_user_info.py USERNAME
- github_user_info.py (-h | --help)
- github_user_info.py (-v | --version)
- Arguments:
- USERNAME Github username
- Options:
- -h --help Show this screen.
- -v --version Show version.
- """
- from docopt import docopt
- import requests
- import sys
- def main():
- if len(sys.argv) == 1:
- sys.argv.append('-h') # Show help screen if no arguments are passed
- cmd_arguments = docopt(__doc__, version='Github User Info v1.0')
- username = cmd_arguments["USERNAME"]
- if len(username.split()) != 1:
- print('Github usernames must be one word in length! Exiting!')
- return
- response = requests.get(f'https://api.github.com/users/{username}')
- if response.status_code != requests.codes.ok:
- if response.status_code == 404: # No such user was found
- print(f'No Github user was found with username {username}!')
- else:
- print(f'An unexpected error occured! Exiting with error code: '
- f'{response.status_code}')
- return
- responses_json = response.json()
- print(f'The following information was found on user: {username}',
- end='nn')
- print(f'Name: {responses_json["name"]}')
- print(f'Bio: {responses_json["bio"]}')
- print(f'Followers: {responses_json["followers"]}')
- print(f'Following: {responses_json["following"]}')
- if __name__ == '__main__':
- main()
- if len(username.split()) != 1:
- print('Github usernames must be one word in length! Exiting!')
- return
- if ' ' in username:
- print('Github usernames cannot contain spaces! Exiting!')
- return
- print(f'The following information was found on user: {username}',
- end='nn')
- print(f'Name: {responses_json["name"]}')
- print(f'Bio: {responses_json["bio"]}')
- print(f'Followers: {responses_json["followers"]}')
- print(f'Following: {responses_json["following"]}')
- print(f'''
- The following information was found on user: {username}
- Name: {responses_json["name"]}
- Bio: {responses_json["bio"]}
- Followers: {responses_json["followers"]}
- Following: {responses_json["following"]}''')
Add Comment
Please, Sign In to add comment