Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Created July 13, 2016 14:20
Show Gist options
  • Save jarmitage/70d4468395a0d7776b06c07c330ac8f8 to your computer and use it in GitHub Desktop.
Save jarmitage/70d4468395a0d7776b06c07c330ac8f8 to your computer and use it in GitHub Desktop.
Convert Scrivener .scrivx file to Emacs org-mode file
import xml.etree.ElementTree as ET
import os
from os.path import join
import io
# 1. Extract Docs and .scrivx from Scrivener using 'Open Package Contents'
# 2. Convert Docs from .rtf to .txt using GNU unrtf and put .txt files in folder called txt
# 3. Run script
dir = 'path/to/scriv'
def parse_scrivx(path):
tree = ET.parse(path)
scrivx = tree.getroot()
walk(scrivx, 'BinderItem')
def walk(tree, tag, depth=0):
for child in tree:
if child.tag == tag:
d = (depth+1)/2
print('*' * int(d), child.find('Title').text)
path = join(dir, "txt", child.attrib['ID'] + ".txt")
if os.path.isfile(path):
with io.open(path, 'r', encoding='ISO-8859-1') as f:
for l in f:
print(l)
walk(child, tag, depth+1)
parse_scrivx('Project.scrivx')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment