Closed kbjarkefur closed 1 year ago
Suggestion for assert on iss_location()
position = iss_location()
assert float(position[0]) and float(position[1])
outputting kenya_data
instead of print(kenya_data)
shows the results more readable
A flavor thing, but I think it is more maintainable code to not use else
here and rely on return
exiting the code. If you were to expand on this function with more complex control flow it is better to do return None
at the bottom of the function outside any control flow.
def fetch_geoboundaries_data(country_code, admin_level):
endpoint = 'https://www.geoboundaries.org/api/current/gbOpen/'
url = endpoint + country_code + '/ADM' + str(admin_level)
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data
print('Request failed!')
return None
It makes a function like this DRYer IMHO (as long as you only have one type of error message):
def fetch_population_by_year(year):
endpoint = 'https://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL'
parameters = {'date': year, 'format':'json'}
response = requests.get(endpoint, params=parameters)
if response.status_code == 200:
data = response.json()
total_obs = data[0]['total']
parameters['per_page'] = total_obs
response = requests.get(endpoint, params=parameters)
if response.status_code == 200:
total_data = response.json()
return total_data
print('Request failed!')
return None
I think we spent too much time in the browser before we got into the colab notebook. Next time maybe we are better off doing the slides first, and then skip the step of showing the APIs in the browser and just show them in the code.
I think it can be neat to show that the API URLs work in the browser as well, but maybe just show once that it works, to show the output, make the point that it looks like something code can parse, and then go into the code and show how it is done in code.
I think we should add a motivation for APIs. Now we mostly say this is API and this is how we use it. I am sure participants can see how it can be useful, but we can show more examples.
Examples:
closing issue as these suggestions were addressed already
Change "the only difference is that the content of an API request will be in JSON format", "the main difference is that the response of an API request will be in data friendly format, such as JSON"