# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Working with APIs in Python
#
# In Python, there are many libraries to make HTTP requests. We will use a 3rd-party library called "requests", which is very easy to use and very popular. 
#
# Making a "GET" request is as simple as: 
#
# ```python
# import requests
#
# res = requests.get(url) # returns a "Response" object
# res.content # has the "body" of the response
# ```
#
# You might need to install the requests library! 
#
# You can do that with the following code in a Jupyter cell: 
#
# ```python
# # ! pip install requests
# ```
#
# Or, if you're using anaconda, optionally you can also do: 
#
# ```python
# # ! conda install -c anaconda requests
# ```

# ## Pokemon API
#
# There is a simple, open API called "pokeapi" that allows us to make requests and see how to use APIs. Like everything, we first look at the documentation: 
#
# https://pokeapi.co/docs/v2.html
#
# The video below will walk you through how to read the documentation page.

# +
from IPython.lib.display import YouTubeVideo

YouTubeVideo('5-li5umLyGM', width=640,height=360)

# +
# Let's see how to make a GET request to the API: 
import requests

# let's take a look at the "Pokemon" resource
res = requests.get('https://pokeapi.co/api/v2/pokemon')

# the .json() method on the Response class essentially
# wraps a call to `json.loads` on the response body 
# for us:
res.json() 

# +
# Exercise 1:
# Create a Dataframe with all the Pokemon names and the URL
# that can be used to get detailed information about them via
# the API:
#
# HINT: Take a look at the "next" property in the JSON API
# response.


# name       | url                   |
# -----------|-----------------------
# bulbasaur  | https://pokeapi.co/api/v2/pokemon/1/
# ...
# squirtle   | https://pokeapi.co/api/v2/pokemon/7/
# ...
# -

# ## Exercise 2: Exchange Rates
#
# Imagine that you work with financial assets which are denominated in different currencies. You analyze this data regularly, and want to create a "transformation" function that transforms all your assets into EUR prices, based on today's exchange rate. 
#
# Your data with the local-currency-denominated value of each asset lives in a file called "assets.csv" which should be located in the same folder as this notebook. 
#
# Write a "data loading" function that: 
#
# 1. Reads the data, given the path to the file. 
# 2. Returns a dataframe with an additional column that has the assets value in euros, as of today.
#
# Use this free API to get today's exchange rates: https://exchangeratesapi.io/. You will need to read the documentation and try it out to see how it works. 
#
# HINT: Write a separate function to get the current exchange rates - a function that can be reused!

StarcoderdataJupyterScriptsDedupFiltered