Community Data Science Workshops (Sprint 2015)/Day 2 lection: Difference between revisions

From CommunityData
(placebear and change to requests.)
(fixed to use bears)
Line 26: Line 26:
#* open files and write to them
#* open files and write to them
# [http://placebear.com/ placebear.com]
# [http://placebear.com/ placebear.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 bears
#* example of placekitten in browser
#* example of placebear in browser
#** visit the API documentation
#** visit the API documentation
#** kittens of different sizes
#** bears of different sizes
#** kittens in greyscale or color
#** bears in greyscale or color
#** bears not your thing? Try [http://placekitten.com/ placekitten] instead!
#* 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

Revision as of 03:11, 23 April 2015

Lecture Outline

  1. Introduction to APIs
    • 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)
      • every API is different, and documented
    • 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
    • lists
    • dictionaries
    • if statements
    • for loops
    • printing
    • modules
  3. New programming concepts:
    • Using requests to access files on the internet
    • interpolate variables into a string using % and %()s
    • open files and write to them
  4. placebear.com
    • API that takes specially crafted URLs and gives appropriately sized picture of bears
    • example of placebear in browser
      • visit the API documentation
      • bears of different sizes
      • bears in greyscale or color
      • bears not your thing? Try placekitten instead!
    • 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: useful for more structure data
    • 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
    • download it and parse it
  6. Other APIs
    • every API is different, so read the documentation!
    • for popular APIs, there are python modules that help you make requests and parse json!
    • rate limiting
    • authenticaiton
    • text encoding issues