Tutorial 7 - Getting Started on P2
Due: March 11 - 11:59 PM
Points: 100 points
Grading: Auto-graded (Can Resubmit)

Submitting

Regardless of how you choose to complete the assignment, you MUST submit the file you worked on to Canvas.

If you’re attending the alternate tutorial (see schedule), please submit your .PY file and make sure your PM has recorded your attendance.

If you’re submitting in-class, make sure to check-in (there will be one question called CHECK-IN Q only available for the first 7 minutes of class) and check-out (there will be a three question survey called CHECKOUT SURVEY only available for the last 10 minutes of class) using PollEverywhere with your location verified.

If you’re submitting out-of-class, please make sure to review the specific submission instructions at the end of Activity 2.


Intro

In this week’s tutorial, we’ll be working on Project 2. This includes:

  1. Setting our computers up to work on P2.
  2. Practicing using some of the modules that have been provided for you inside of the apis directory.

NOTE: While you may complete the Project submissions as a team, this tutorial should be completed solo (i.e. everyone needs to setup their computer so it’s capable of working on the project).

Inside of project 2, we have multiple libraries available which makes importing and using these libraries a little funky. We import things in a familiar way…

from apis import audio

But because there are multiple libraries available in our apis folder (e.g. gui, yelp, movies, twilio, and audio), when we call the functions in these apis we still have to specify which library they come from when we call them. So for example if I want to use the get_genres function of the audio api, then we have to call it by saying audio.get_genres.... If I want to use print from the gui library, then I have to call it by saying gui.print(..., etc.

For all of the API functions in P2, you must use the syntax library_name.function_name(...).

Please complete the following steps:


Activity 0. Getting Setup

Complete the “Setup” section of Project 2.

When you’re done, complete one of the three options (either / or) listed below:


Activity 1a (Yelp)

Yelp Docs

Create a brand new file called tutorial7.py directly inside of your project2 folder (the location matters). Your directory structure should look like this:

├── apis
├── restaurant_finder.py
├── tests
└── tutorial7.py

Next, paste the following code into your tutorial7.py file and run it.

from apis import yelp

businesses = yelp.get_businesses("Evanston, IL")
print(businesses)

You should see some Evanston restaurants print to the interpreter window (as a list of dictionaries).


Practice Outputting Dictionary Values

  1. Output just the name of each business to the interpreter window.
  2. Output the name, rating, and review_count to the interpreter window.

Using Helper Functions

There is also a helper function inside of the apis.yelp module that can help you output businesses to the interpreter window, which you are welcome to modify:

table_text = yelp.generate_businesses_table(businesses)
print(table_text)

Practice Querying

When you’re done outputting the data up the Yelp documentation and navigate down to the get_businesses function. Note all of the keyword (optional) parameters that the function accepts.

Next, go back to your tutorial7.py file and modify the get_businesses(…) function call by:

  1. Use the various keyword arguments (price, category, and/or location) to change which results get displayed.
  2. Use the sort_by keyword argument to change the sort order.

Activity 1b (Movies)

🎥 Movie Docs

Create a brand new file called tutorial7.py directly inside of your project2 folder (the location matters). Your directory structure should look like this:

├── apis
├── watchlist_maker.py
├── tests
└── tutorial7.py

Next, paste the following code into your tutorial7.py file and run it.

from apis import movies
upcoming_movies = movies.get_upcoming()
print(upcoming_movies)

You should see some movies print to the interpreter window (as a list of dictionaries). These are movies that coming to theaters soon.


Practice Outputting Dictionary Values

  1. Output just the title of each movie to the interpreter window
  2. Output the title, id, and release-date to the interpreter window

Practice Querying

When you’re done outputting the data, open the Movies documentation and navigate down to the generate_watchlist function. Note all of the keyword (optional) parameters that the function accepts.

While each parameter is technically optional, this function needs some seed data in order to give you song recommendations. Go back to your tutorial7.py file and try invoking the mvoies.generate_watchlist function as follows:

watchlist = movies.generate_watchlist(genres=[ 'Adventure' ])
print(watchlist)

There is also a helper function inside of the apis.movies module that can help you output the tracks to the interpreter window:

table_text = movies.generate_movie_table(watchlist)
print(table_text)

Activity 1c (Audio)

Audio Docs

Create a brand new file called tutorial7.py directly inside of your project2 folder (the location matters). Your directory structure should look like this:

├── apis
├── mixtape_maker.py
├── tests
└── tutorial7.py

Next, paste the following code into your tutorial7.py file and run it.

from apis import audio
artists = audio.search_for_artists('Beyonce')
print(artists)

You should see some search results relating to Beyonce print to the interpreter window (as a list of dictionaries).


Practice Outputting Dictionary Values

  1. Output just the name of each artist to the interpreter window
  2. Output the name, genres, and share_url to the interpreter window

Practice Querying

When you’re done outputting the data, open the Spotify documentation and navigate down to the generate_mixtape function. Note all of the keyword (optional) parameters that the function accepts.

While each parameter is technically optional, this function needs some seed data in order to give you song recommendations. Go back to your tutorial7.py file and try invoking the audio.generate_mixtape function as follows:

track_recommendations = audio.generate_mixtape(artist_ids=['6vWDO969PvNqNYHIOW5v0m'])
print(track_recommendations)

There is also a helper function inside of the apis.audio module that can help you output the tracks to the interpreter window:

table_text = audio.generate_tracks_table(track_recommendations)
print(table_text)

If you still have time, please experiment with some of the other built-in functions:


Activity 2. Using the GUI Library

🐍 GUI Docs

For the real project, we don’t want to print stuff to the interpreter window. Instead, we want to use the GUI library to help us make a real app! Once you get comfortable with the above, open up either restaurant_finder.py or mixtape_generator.py and take a look at the template.

Adapt some of your work from the above exercises to fit the template – moving your code into one of the “button” functions and replacing calls to the print function with calls to gui.print (which works exactly like print…but shows it on the app’s GUI rather than in the interpreter window).

Next, try out the gui.input function (which works exactly like input…but uses a popup window to ask the user to type something in).

Next, try out the gui.numeric_input function (which works exactly like input…but uses a popup window to ask the user to select a numeric value).

Finally, try out the gui.popup function which shows a popup window with a message in-case you want to give the user a warning or message outside of the window.

Note: if you're completing this remotely, you can just submit a screenshot of the versions of Activity 1 working in your GUI window RATHER than the Interpreter window (like in the demo vids for each project).


Other Practice

Some other things that might be useful during project 2!

# Printing all of the different things in a list one on each line:
counter = 0
my_list = ["a", "b", "c", "d"]
for item in my_list:
    print(counter, item)
    counter = counter + 1

# Printing all of the different key value pairs in a dictionary one by one:
my_dict = {"a": 1, "b":2, "c": 3}
for key in my_dict:
    print(key, my_dict[key])
# Splitting a string of numbers separated by commas into a list of strings
test = "1,2,3,4,5"
my_list = test.split(",")
# Making a list of numbers or things into a string separated by commas.
my_list = [1, 2, 3, 4, 5]
my_string = ",".join(my_list)
# Converting strings to an integer
a_string = "1"
try:
    an_int = int(a_string)
except:
    print("PANICCCCCC!")
# Short circuiting a function...
def example_function(a_number):
    if a_number == 2:
        return None
    print("I'll only print if the number isn't 2")
    return "hello"