Hello world!
from random import random
import hashlib
def randhash():
m = hashlib.sha1()
m.update(str(random()))
return m.hexdigest()[:6]
import os
ind = '/Users/caporaso/temp/An-Introduction-To-Applied-Bioinformatics-master/'
d = 'book'
try:
os.makedirs('./%s' % d)
except OSError:
pass
cmd = "ipython nbconvert %s --to markdown --output %s"
for root, dirs, files in os.walk(ind):
out_root = root.replace(ind, "")
for f in files:
if '.ipynb_checkpoints' in root: continue
fn, ext = os.path.splitext(f)
if ext =='.ipynb':
try:
os.makedirs(os.path.join(d, out_root))
except OSError:
pass
inf = os.path.join(root, f)
outf = os.path.join(d, out_root, '%s.md' % fn)
x = cmd % (inf, outf)
y = !$x
lines = open(outf)
out_lines = []
in_code = False
for line in lines:
line = line.strip('\n')
if line.startswith(' '):
if not in_code:
in_code = True
out_lines.append('```python')
line = line[4:]
if len(line) > 0:
out_lines.append('>>> %s' % line)
else:
out_lines.append('...')
else:
if in_code:
in_code = False
out_lines.append('```')
if line.startswith('#'):
out_lines.append("%s <link src='%s'/> "% (line, randhash()))
else:
out_lines.append(line)
if in_code:
out_lines.append('```')
outs = '\n'.join(out_lines)
outs = outs.replace('\n\n\n', '\n\n')
open(outf, 'w').write(outs)
print "***WROTE: %s" % outf
***WROTE: book/Index.md ***WROTE: book/applications/biological-diversity.md ***WROTE: book/fundamentals/database-searching.md ***WROTE: book/fundamentals/msa-assignment.md ***WROTE: book/fundamentals/multiple-sequence-alignment.md ***WROTE: book/fundamentals/pairwise-alignment-exercises.md ***WROTE: book/fundamentals/pairwise-alignment.md ***WROTE: book/fundamentals/phylogeny-reconstruction.md ***WROTE: book/fundamentals/sequence-mapping-and-clustering.md ***WROTE: book/getting-started/reading-iab.md
'021fa4'