Skip to content

Instantly share code, notes, and snippets.

@anandology
Created October 21, 2011 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/1303809 to your computer and use it in GitHub Desktop.
Save anandology/1303809 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import json
import urllib
def jsonget(url):
text = urllib.urlopen(url).read()
return json.loads(text)
def get_edition(key):
url = "http://openlibrary.org" + key + ".json"
return jsonget(url)
def edtions_of_work(key):
url = "http://openlibrary.org" + key + "/editions.json?limit=1000"
return jsonget(url)['entries']
def editions_of_list(url):
editions = []
seeds = jsonget(url + "/seeds.json")['entries']
for seed in seeds:
if seed['type'] == 'work':
editions.extend(edtions_of_work(seed['url']))
elif seed['type'] == 'edition':
editions.append(get_edition(seed['url']))
return editions
def main():
url = "http://openlibrary.org/people/krisneg/lists/OL11238L"
print json.dumps(editions_of_list(url), indent=2)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment