Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created December 15, 2010 03:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyeseast/741567 to your computer and use it in GitHub Desktop.
Save eyeseast/741567 to your computer and use it in GitHub Desktop.
A simple python wrapper for the DocumentCloud API
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