Created
March 19, 2021 15:05
-
-
Save morisy/d3cb61c028aa379665f511d40b2added to your computer and use it in GitHub Desktop.
Export notes from a given DocumentCloud document into a spreadsheet
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 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