Editing Community Data Science Workshops (Spring 2015)/Day 2 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:
[[File:Place bear-500x650.jpeg|200px|thumb|In which you learn how to use Python and web APIs to meet the likes of these guys!]]
[[File:Place bear-500x650.jpeg.jpeg|200px|thumb|In which you learn how to use Python and web APIs to meet the likes of these guys!]]


== Lecture Outline ==
== Lecture Outline ==
Line 12: Line 12:


* What did we learn in Session 1?
* What did we learn in Session 1?
* New data type: Tuple!
* What is an API?
* What is an API?
* How do we use one to fetch interesting datasets?
* How do we use one to fetch interesting datasets?
Line 65: Line 66:
; New programming concepts:
; New programming concepts:


* interpolate variables into a string using format
* interpolate variables into a string using % and %()s
* [http://docs.python-requests.org/en/latest/ requests]
* requests
* open files and write to them
* open files and write to them
* parsing a string (turning the string into a data structure we can manipulate) using the json module
* parsing a string (turning the string into a data structure we can manipulate)




Line 79: Line 80:
** bears of different sizes
** bears of different sizes
** bears in greyscale or color
** bears in greyscale or color
* Now we write a small program to grab an arbitrary square from placebear by asking for the size on standard in ([http://mako.cc/teaching/2015/cdsw-spring/placebear_input.py placebear_input.py])
* Now we write a small program to grab an arbitrary square from placebear by asking for the size on standard in ([http://mako.cc/teaching/2015/cdsw-spring/placebear_raw_input.py placebear_raw_input.py])




Line 85: Line 86:


* what is json: useful for more structured data
* what is json: useful for more structured data
* import json; json.loads(), or, even easier, just do it directly with requests using the <code>.json()</code> function!
* import json; json.loads()
* like Python (except no single quotes)
* like Python (except no single quotes)
* simple lists, dictionaries
* simple lists, dictionaries
Line 108: Line 109:
* [http://mako.cc/teaching/2014/cdsw-autumn/lecture2-web_apis.pdf Slides (PDF)] — For viewing
* [http://mako.cc/teaching/2014/cdsw-autumn/lecture2-web_apis.pdf Slides (PDF)] — For viewing
* [http://mako.cc/teaching/2014/cdsw-autumn/lecture2-web_apis.odp Slides (ODP Libreoffice Slides Format)] — For editing and modification
* [http://mako.cc/teaching/2014/cdsw-autumn/lecture2-web_apis.odp Slides (ODP Libreoffice Slides Format)] — For editing and modification
[[Category:Spring_2015_series]]
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)