Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
About
People
Publications
Teaching
Resources
Research Blog
Wiki Functions
Recent changes
Help
Licensing
Page
Discussion
Edit
View history
Editing
Community Data Science Course (Spring 2023)/Week 4 lecture notes
(section)
From CommunityData
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Our first API: Bored API == * First of all, lets check out this page: http://www.boredapi.com/ ** Let's click through the about page and the documentation and try stuff on their web interface *** Try the random endpoint *** The output is JSON * JSON ** HTML versus JSON ** The good news is that JSON is (almost!) the same as Python! Just lists, strings, dictionaries, integers, floats, etc. (e.g., What type is key? ** Most APIs will return JSON directly ** It's often helpful to format JSON to understand it * Passing parameters to an API ** let's go back and look at the documentation ** lets request things based on a specific number of participants ** lets try to request thing based on a price range (give you all 3-4 minutes to try) * Making requests in Python ** <code>import requests</code> ** <code>response = requests.get(URL, params={})</code> ** <code>print(response.status_code)</code>. it also contains .url which is pretty useful! ** <code>data = response.json()</code>; now we can check type and poke around in it (I typically use tab completion!) * e.g., lets work through a quick example ** Let's put it into a Python program to print out one activity for 1 through 5 people! ** Let's add the type of activity to what we print out ** Let's add another parameter (maybe a price range?) ** Let's show how to add parameters via dictionaries
Summary:
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see
CommunityData:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information