GitHub API Assignment

For this assignment you are to create a Python command line application similar to starwars_person_search.py that we looked at in class before break. Instead of using the Star Wars API, you will be using the GitHub API, and instead of listing search results for people you will be listing a GitHub user’s public repositories.

The URL to get a user’s repositories is as follows:

https://api.github.com/users/<username>/repos

Replace <username> with the name of the user you are looking up.

For example, here is how to fetch my repositories. Try putting this URL in your browser, and examine the JSON structure:

https://api.github.com/users/sommern/repos

You will need to run your code using a virtual environment that has the requests module isntalled. The function requests.get() returns a Response object. The example from class shows how you can use the json() method of a Response object to get the JSON content of the response as a Python object that is composed of nested lists and dictionaries.

The Response object also contains a status_code attribute. The status code of an HTTP response indicates if there was an error in the request or not. If the response code is 200, everything went OK. If it is 404, you either typed the URL wrong or the user does not exist.

Your code should exit the program by passing an error message to sys.exit() if the user uses the wrong number of command line arguments, or if the status code of the response is not 200.

Example Output

Below are some examples of the behavior your program should exhibit. The examples show the command that one would run in the terminal to run the program. On a Mac you can use the “Terminal” tab at the bottom of PyCharm to open a terminal and run the program as shown. If you are in Windows and using WSL or Cygwin, this will not work. To add the username as a command line argument when running the program you will need to click on the dropdown list in the upper right of PyCharm and select “Edit Configuration”. Then place the argument in the “Parameters” field.

Normal behavior:

$ python3 list_repos.py sommern 
anotherpushtest
git-keeper
GitExperiments
homebrew-repo
larasynth
midifile
mkdocs_test
projects_test
PycharmEduDemo
readerwriterqueue

Missing command line argument:

$ python3 list_repos.py
Usage: list_repos.py <username>

Invalid user:

$ python3 list_repos.py NonexistantUser
Error fetching repositories for user NonexistantUser

Submission

Push your code to git-keeper. Correctness and PEP 8 compliance will be tested automatically.