Editing DS4UX (Spring 2016)/Day 5 lecture

From CommunityData
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.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
<div style="font-family:Rockwell,'Courier Bold',Courier,Georgia,'Times New Roman',Times,serif; min-width:10em;">
<div style="float:left; width:100%; margin-right:2%;">
{{Link/Graphic/Main/2
|highlight color= 27666b
|color=460c40
|link=
|image=
|text-align=left
|top font-size= 1.1em
|top color=FFF
|line color=FFF
|top text=This page is a work in progress.
|bottom font-size= 1em
|bottom color= FFF
|bottom text=
|line= none
}}</div></div>
<div style="clear:both;"></div>
[[File:Highfivekitten.jpeg|200px|thumb|In which you learn how to use Python and web APIs to meet the likes of her!]]
[[File:Highfivekitten.jpeg|200px|thumb|In which you learn how to use Python and web APIs to meet the likes of her!]]


Line 24: Line 46:


== Lecture 1: What is an API? ==
== Lecture 1: What is an API? ==
''RAY: the content below is just for your reference. You can delete it or replace it as you see fit! [[User:Jtmorgan|Jtmorgan]] ([[User talk:Jtmorgan|talk]]) 16:57, 21 April 2016 (EDT)''


* API: a structured way for programs to talk to each other (aka an interface for programs)
* API: a structured way for programs to talk to each other (aka an interface for programs)
* Web APIs: like a website your programs can visit (you:a website::your program:a web API)
* Web APIs: like a website your programs can visit (you:a website::your program:a web API)


=== Download the Week 5 lecture scripts and data ===
<big>'''[http://jtmorgan.net/ds4ux/week5/lecture.zip Click here to download the week 5 lecture scripts and data examples]'''</big>
# The ".zip" extension on the above file indicates that it is a compressed Zip archive. We need to "extract" its contents.
# Start up your terminal, navigate to the new directory you have unpacked called <code>lecture</code>


=== How do we use an API to fetch datasets? ===
=== How do we use an API to fetch datasets? ===
Line 58: Line 76:
** kittens of different sizes
** kittens of different sizes
** kittens in greyscale or color
** kittens in greyscale or color
* Now we are ready to walk through a small program (<code>placekitten_input.py</code>) that grabs a random picture from placekitten.com of a user-specified height and width, and saves that image as a .jpg image on your computer.
* Now we write a small program to grab an arbitrary square from placekitten by asking for the size on standard in: [http://mako.cc/teaching/2014/cdsw-autumn/placekitten_raw_input.py placekitten_raw_input.py]
 
 


== Lecture 2: Using data from APIs in Python ==
== Lecture 2: Using data from APIs in Python ==
 
''RAY: the content below is just for your reference. You can delete it or replace it as you see fit! [[User:Jtmorgan|Jtmorgan]] ([[User talk:Jtmorgan|talk]]) 16:57, 21 April 2016 (EDT)''


=== How do we write Python programs that make web requests? ===
=== How do we write Python programs that make web requests? ===
Line 75: Line 95:


* what is json: useful for more structured data
* what is json: useful for more structured data
* import json; json.load(), json.loads()
* import json; json.loads()
* like Python (except no single quotes)
* like Python (except no single quotes)
* simple lists, dictionaries
* simple lists, dictionaries
* can reflect more complicated data structures
* can reflect more complicated data structures
* Example file at http://mako.cc/cdsw.json
* You can parse data directly with <code>.json()</code> on a <code>requests</code> call
* You can parse data directly with <code>.json()</code> on a <code>requests</code> call
* You can parse JSON files with <code>json.load()</code>
* You can parse JSON ''strings'' with <code>json.loads()</code> (the 's' is for 'string')
* Example JSON file: <code>family.json</code>
* script to parse this file into a CSV: <code>family_json_to_csv.py</code>
* script to parse and print a ''JSON string'' version of this example file: <code>parse_json.py</code>


=== Using other APIs ===
=== Using other APIs ===
Line 98: Line 114:




== Week 5 project: How do we use APIs to get data from Wikipedia? ==
== Exercise 2: How do we use APIs to get data from Wikipedia? ==
* Brief intro to Wikipedia
* Brief intro to Wikipedia
* Overview of what you can get from [[DS4UX_(Spring_2016)/Wikipedia_API|the Wikipedia API]]
* Overview of what you can get from the Wikipedia API
* Example queries in the [https://en.wikipedia.org/wiki/Special:ApiSandbox Wikipedia API sandbox]
* Harry Potter examples
* Introduce [[DS4UX_(Spring_2016)/Day_5_coding_challenge|week 5 coding challenges]]
* Introduce coding challenges
 
 
 


[[Category:DS4UX (Spring 2016)]]
[[Category:DS4UX (Spring 2016)]]
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)