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

From OpenHatch wiki
Content added Content deleted
imported>Mako
No edit summary
imported>Mako
Line 2: Line 2:


# API
# API
#* definition of an API in general
#* definition of API: just an interface for programs
#* definition of web API for data
#* definition of web API
#** way to ask for data (almost always a URL)
#** way to get data back (almost always in a format called JSON)
#* to use APIs to build a dataset we will need:
#** all our tools from last session: variables, etc
#** the ability to open urls on the web
#** the ability to create custom URLS
#** the ability to save to files
#** the ability to understand (i.e., parse) JSON data that APIs usually give us
# Review material from last session
# Review material from last session
#* variables, different types
#* variables, different types
Line 16: Line 24:
#* urllib2 and urlopen
#* urllib2 and urlopen
#* interpolate variables into a string using % and %()s
#* 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
# [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
Line 31: Line 31:
#* show how to use place
#* show how to use place
#* write a small program to grab arbitrary square from placekitten by asking for the size on standard in
#* write a small program to grab arbitrary square from placekitten by asking for the size on standard in
# 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
# Wikipedia API
# Wikipedia API
#* explain MediaWiki, exists on other wikis
#* explain MediaWiki, exists on other wikis

Revision as of 13:21, 3 May 2014

Lecture Outline

  1. API
    • definition of API: just an interface for programs
    • definition of web API
      • way to ask for data (almost always a URL)
      • way to get data back (almost always in a format called JSON)
    • to use APIs to build a dataset we will need:
      • all our tools from last session: variables, etc
      • the ability to open urls on the web
      • the ability to create custom URLS
      • the ability to save to files
      • the ability to understand (i.e., parse) JSON data that APIs usually give us
  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
  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. 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
  6. Wikipedia API
  7. Other APIs
    • every API is different, so read the documentation!
    • rate limiting
    • authenticaiton
    • text encoding issues