Skip to content

Instantly share code, notes, and snippets.

@morisy
Created March 19, 2021 15:05
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 morisy/d3cb61c028aa379665f511d40b2added to your computer and use it in GitHub Desktop.
Save morisy/d3cb61c028aa379665f511d40b2added to your computer and use it in GitHub Desktop.
Export notes from a given DocumentCloud document into a spreadsheet
import requests
import csv
from documentcloud import DocumentCloud # https://documentcloud.readthedocs.io/en/latest/gettingstarted.html#installation
# Install DocumentCloud Python Wrapper first: https://documentcloud.readthedocs.io/en/latest/index.html
USERNAME = input('Username: ')
PASSWORD = input('Password: ')
client = DocumentCloud(USERNAME, PASSWORD)
documentID = input('Document ID: ')
obj = client.documents.get(documentID)
with open('notes for doc ' + str(documentID) + '.csv', 'w', newline='') as csvfile:
fieldnames = ['title', 'note', 'page', 'id']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
for note in obj.annotations:
writer.writerow({'title': note.title, 'note': note.content, 'page': note.page, 'id': note.id})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment