Created
July 13, 2016 14:20
-
-
Save jarmitage/70d4468395a0d7776b06c07c330ac8f8 to your computer and use it in GitHub Desktop.
Convert Scrivener .scrivx file to Emacs org-mode file
This file contains 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 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