Created
October 21, 2011 13:09
-
-
Save anandology/1303809 to your computer and use it in GitHub Desktop.
Script to export editions from http://openlibrary.org/people/krisneg/lists/OL11238L/Civil_War_Regiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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