Skip to content
Snippets Groups Projects
Commit 75422fc0 authored by jhjung's avatar jhjung
Browse files

v0.1.7

parent 04eaf53c
No related branches found
No related tags found
No related merge requests found
import json, base64, os, pickle, datetime, string, re import json, base64, os, pickle, datetime, string, re
__version__ = "0.1.4" __version__ = "0.1.7"
### from ipynb extract markdown and noted output for document organization ### from ipynb extract markdown and noted output for document organization
class nbparser: class nbparser:
...@@ -16,7 +16,7 @@ class nbparser: ...@@ -16,7 +16,7 @@ class nbparser:
self.notebook = json.loads("\n".join(open(path).readlines())) self.notebook = json.loads("\n".join(open(path).readlines()))
self.outroot = os.path.join(output_root,"source") self.outroot = os.path.join(output_root,"source")
self.opath = os.path.join(self.outroot, self.folder, self.basename) self.opath = os.path.join(self.outroot, self.folder, self.basename)
os.makedirs(self.opath, exist_ok = True)
self.TOC, self.source = [],[] self.TOC, self.source = [],[]
self.fig, self.code = [], [] self.fig, self.code = [], []
self.table = [] self.table = []
...@@ -109,6 +109,7 @@ class nbparser: ...@@ -109,6 +109,7 @@ class nbparser:
self.save_fig(self.outputpath(fname), data['data'][key]) self.save_fig(self.outputpath(fname), data['data'][key])
def save_fig(self, fname, base64fig): def save_fig(self, fname, base64fig):
os.makedirs(self.opath, exist_ok = True)
with open(fname,"wb") as f: with open(fname,"wb") as f:
f.write(base64.b64decode(base64fig)) f.write(base64.b64decode(base64fig))
...@@ -196,7 +197,7 @@ class nbparser: ...@@ -196,7 +197,7 @@ class nbparser:
return s return s
def source_convert(self): def source_convert(self):
source = [line if not line =="!TOC" else self.toc_source() for line in self.source] # Table of Contents source = [line if not line =="!TOC" else self.toc_source() for line in self.source if line] # Table of Contents
source = "\n\n".join(source) source = "\n\n".join(source)
# double bracket to ref # double bracket to ref
...@@ -217,10 +218,10 @@ class nbparser: ...@@ -217,10 +218,10 @@ class nbparser:
def write_markdown(self): def write_markdown(self):
source = self.source_convert() source = self.source_convert()
if source:
### Write markdown ### Write markdown
with open(self.fname,"w") as f: with open(self.fname,"w") as f:
f.write(source) f.write(source)
def toc_source(TOC): def toc_source(TOC):
...@@ -243,7 +244,8 @@ def daily_note(note_path, check): ...@@ -243,7 +244,8 @@ def daily_note(note_path, check):
source = pickle.load(f) source = pickle.load(f)
mod, record = modified_check(source, check) mod, record = modified_check(source, check)
write_daily(note_path, mod, record) if mod:
write_daily(note_path, mod, record)
def modified_check(source, check): def modified_check(source, check):
mod = {} mod = {}
...@@ -299,7 +301,12 @@ rm __tmp__files ...@@ -299,7 +301,12 @@ rm __tmp__files
cd wiki cd wiki
git add * git add *
if [ `git diff --cached --name-only| wc -l` -eq 0 ]
then
echo "nothing to commit"
else
git commit -m "Auto commit from nbresnote `date +%F`" git commit -m "Auto commit from nbresnote `date +%F`"
fi
""" """
pushsource = """#!/bin/bash pushsource = """#!/bin/bash
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment