Community Data Science Workshops (Spring 2014)/Saturday May 3rd lecture: Difference between revisions
Content added Content deleted
imported>Mako |
imported>Mako |
||
Line 18: | Line 18: | ||
#* urllib2 and urlopen |
#* urllib2 and urlopen |
||
#* JSON file (JavaScript Object Notation) |
#* JSON file (JavaScript Object Notation) |
||
#** import json; json.loads() |
|||
⚫ | |||
#** |
#** like Python (except no single quotes) |
||
#** |
#** simple lists, dictionaries |
||
#** can reflect more complicated data structures |
#** can reflect more complicated data structures |
||
⚫ | |||
# API |
# API |
||
#* definition of an API in general |
#* definition of an API in general |
Revision as of 03:31, 3 May 2014
Lecture Outline
- Review material from last session
- variables, different types
- printing
- if statements
- lists
- dictionaries
- for loops
- modules
- example python program
- New programming concepts:
- open a file and write to it
- open a file and append to it
- join a string together
- interpolate variables into a string using % and %()s
- from syntax for importing
- urllib2 and urlopen
- JSON file (JavaScript Object Notation)
- 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
- API
- definition of an API in general
- definition of web API for data
- 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
- Wikipedia API
- explain MediaWiki, exists on other wikis
- navigate to api page and show the documentation, point out examples
- looking at the images within a page http://en.wikipedia.org/w/api.php?action=query&titles=Seattle&prop=images&imlimit=20&format=jsonfm
- looking at within two pages http://en.wikipedia.org/w/api.php?action=query&titles=Seattle%7CBellevue,_Washington&prop=images&imlimit=50&format=jsonfm
- edit count http://en.wikipedia.org/w/api.php?action=query&list=users&ususers=Benjamin_Mako_Hill%7CJtmorgan%7CSj%7CMindspillage&usprop=editcount&format=jsonfm
- give me the content of the main page http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Main%20Page&prop=revisions&rvprop=content
- Other APIs
- every API is different, so read the documentation!
- rate limiting
- authenticaiton
- text encoding issues