Skip to content

Instantly share code, notes, and snippets.

@bllchmbrs
Created December 2, 2014 01:52
Show Gist options
  • Save bllchmbrs/09c421e3ff13e1245316 to your computer and use it in GitHub Desktop.
Save bllchmbrs/09c421e3ff13e1245316 to your computer and use it in GitHub Desktop.
Convert Markdown Files to Quiver notes
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)
@pl0
Copy link

pl0 commented Dec 12, 2014

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.

@bllchmbrs
Copy link
Author

@pl0

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