Difference between revisions of "Community Data Science Workshops (Spring 2014)/Saturday May 3rd lecture"

From OpenHatch wiki
Jump to navigation Jump to search
imported>Mako
imported>Mako
Line 14: Line 14:
 
#* example python program
 
#* example python program
 
# New programming concepts:
 
# New programming concepts:
#* open a file and write to it
+
#* urllib2 and urlopen
#* join a string together
 
 
#* interpolate variables into a string using % and %()s
 
#* interpolate variables into a string using % and %()s
#* urllib2 and urlopen
+
#* JSON file (JavaScript Object Notation)
# JSON file (JavaScript Object Notation)
+
#** what is json
#* what is json
+
#** import json; 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
 
#* Example file at http://mako.cc/cdsw.json
 +
#* open a file and write to it
 
# [http://placekitten.com/ placekitten.com]
 
# [http://placekitten.com/ placekitten.com]
 
#* API that takes specially crafted URLs and gives appropriately sized picture of kittens
 
#* API that takes specially crafted URLs and gives appropriately sized picture of kittens

Revision as of 04:54, 3 May 2014

Lecture Outline

  1. API
    • definition of an API in general
    • definition of web API for data
  2. Review material from last session
    • variables, different types
    • printing
    • if statements
    • lists
    • dictionaries
    • for loops
    • modules
    • example python program
  3. New programming concepts:
    • urllib2 and urlopen
    • interpolate variables into a string using % and %()s
    • JSON file (JavaScript Object Notation)
      • what is json
      • import json; json.loads()
      • like Python (except no single quotes)
      • simple lists, dictionaries
      • can reflect more complicated data structures
    • Example file at http://mako.cc/cdsw.json
    • open a file and write to it
  4. placekitten.com
    • API that takes specially crafted URLs and gives appropriately sized picture of kittens
    • example of placekitten in browser
      • kittens of different sizes
      • kittens in greyscale or color
    • show how to use place
    • write a small program to grab arbitrary square from placekitten by asking for the size on standard in
  5. Wikipedia API
  6. Other APIs
    • every API is different, so read the documentation!
    • rate limiting
    • authenticaiton
    • text encoding issues