Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Aug 11th, 2018 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/usr/bin/env python3
  2.  
  3. """Github User Info
  4.  
  5. Get basic information on a Github user
  6.  
  7. Usage:
  8.   github_user_info.py USERNAME
  9.   github_user_info.py (-h | --help)
  10.   github_user_info.py (-v | --version)
  11.  
  12. Arguments:
  13.   USERNAME     Github username
  14.  
  15. Options:
  16.   -h --help     Show this screen.
  17.   -v --version  Show version.
  18. """
  19.  
  20. from docopt import docopt
  21. import requests
  22.  
  23. import sys
  24.  
  25.  
  26. def main():
  27.     if len(sys.argv) == 1:
  28.         sys.argv.append('-h')  # Show help screen if no arguments are passed
  29.  
  30.     cmd_arguments = docopt(__doc__, version='Github User Info v1.0')
  31.  
  32.     username = cmd_arguments["USERNAME"]
  33.  
  34.     if len(username.split()) != 1:
  35.         print('Github usernames must be one word in length! Exiting!')
  36.         return
  37.  
  38.     response = requests.get(f'https://api.github.com/users/{username}')
  39.  
  40.     if response.status_code != requests.codes.ok:
  41.         if response.status_code == 404:  # No such user was found
  42.             print(f'No Github user was found with username {username}!')
  43.         else:
  44.             print(f'An unexpected error occured! Exiting with error code: '
  45.                   f'{response.status_code}')
  46.         return
  47.  
  48.     responses_json = response.json()
  49.  
  50.     print(f'The following information was found on user: {username}',
  51.           end='nn')
  52.     print(f'Name: {responses_json["name"]}')
  53.     print(f'Bio: {responses_json["bio"]}')
  54.     print(f'Followers: {responses_json["followers"]}')
  55.     print(f'Following: {responses_json["following"]}')
  56.  
  57.  
  58. if __name__ == '__main__':
  59.     main()
  60.    
  61. if len(username.split()) != 1:
  62.         print('Github usernames must be one word in length! Exiting!')
  63.         return
  64.    
  65. if ' ' in username:
  66.         print('Github usernames cannot contain spaces! Exiting!')
  67.         return
  68.    
  69. print(f'The following information was found on user: {username}',
  70.       end='nn')
  71. print(f'Name: {responses_json["name"]}')
  72. print(f'Bio: {responses_json["bio"]}')
  73. print(f'Followers: {responses_json["followers"]}')
  74. print(f'Following: {responses_json["following"]}')
  75.    
  76. print(f'''
  77. The following information was found on user: {username}
  78.  
  79. Name: {responses_json["name"]}
  80. Bio: {responses_json["bio"]}
  81. Followers: {responses_json["followers"]}
  82. Following: {responses_json["following"]}''')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top