Created
December 15, 2010 03:00
-
-
Save eyeseast/741567 to your computer and use it in GitHub Desktop.
A simple python wrapper for the DocumentCloud API
This file contains hidden or 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
import httplib2 | |
import urllib | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
# create a global Http object so we can reuse connections | |
http = httplib2.Http('.cache') | |
def search(q, page=1, sections=False, annotations=False): | |
""" | |
Search for documents on DocumentCloud | |
""" | |
base = "http://www.documentcloud.org/api/search.json?" | |
params = { | |
'q': q, | |
'page': page, | |
'sections': sections, | |
'annotations': annotations | |
} | |
resp, content = http.request(base + urllib.urlencode(params)) | |
results = json.loads(content) | |
return results.get('documents') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment