Created
December 2, 2014 01:52
-
-
Save bllchmbrs/09c421e3ff13e1245316 to your computer and use it in GitHub Desktop.
Convert Markdown Files to Quiver notes
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 argparse | |
import json | |
import re | |
import os | |
from time import time | |
parser = argparse.ArgumentParser(description='Convert to Quiver Format') | |
parser.add_argument("src", help="The Source File You want to Convert") | |
args = parser.parse_args() | |
cells = [] | |
lines = [] | |
with open(args.src) as f: | |
for row in f.readlines(): | |
lines.append(row) | |
markdown = re.findall(r"`?`?`?([^`]*)```py", ''.join(lines)) | |
code = re.findall(r"```py([^`]*)```", ''.join(lines)) | |
length = len(markdown) | |
markdown_start = True | |
if len(code) > length: | |
length = len(code) | |
markdown_start = False | |
for x in range(length): | |
try: | |
if markdown_start: | |
cells.append({ | |
"type": "markdown", | |
"data": markdown[x].strip("\n") | |
}) | |
cells.append({ | |
"type": "code", | |
"language": "python", | |
"data": code[x].strip("\n") | |
}) | |
else: | |
cells.append({ | |
"type": "code", | |
"language": "python", | |
"data": code[x].strip("\n") | |
}) | |
cells.append({ | |
"type": "markdown", | |
"data": markdown[x].strip("\n") | |
}) | |
except: | |
pass | |
content = {"title": args.src.split('.')[0], "cells": cells} | |
meta = { | |
"created_at" : int(time()), | |
"tags" : [], | |
"title" : args.src.split('.')[0], | |
"updated_at" : int(time()) | |
} | |
newpath = args.src.split('.')[0] + '.qvnote' | |
if not os.path.exists(newpath): os.makedirs(newpath) | |
with open(args.src.split('.')[0] + '.qvnote' + "/content.json", 'wb') as f: | |
json.dump(content, f) | |
with open(args.src.split('.')[0] + '.qvnote' + "/meta.json", 'wb') as f: | |
json.dump(content, f) | |
# print content | |
# with open("content.json", 'wb') as f: | |
# json.dump(content, f) |
it gets the title from the file title. see in the code where it mentions "content" on line 50?
Just change that to be something else, For example you make it the first line by making
content = {"title": lines[0], "cells": cells}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - I partly got this to work but it only seems to import the title of the note, not the content. I'm trying to import my 1000s of nvALT text files into Quiver. Any help much appreciated.