forked from johnmcdonnell/Git-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildBlogPost.py
82 lines (48 loc) · 1.26 KB
/
BuildBlogPost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <headingcell level=1>
# Showoff Presentation -> Blog Post
# <headingcell level=2>
# Setup
# <headingcell level=3>
# Configuration
# <codecell>
config_fn = "showoff.json"
outfile = "blogpost/blogpost.md"
# <headingcell level=3>
# Helper Functions
# <codecell>
# [[a]] -> [a]
def flatten(l):
return [item for sublist in l for item in sublist]
def concatstrings(x):
addtwo = lambda x,y: x + y
return reduce(addtwo, x, "")
# String -> IO [String]
ls = os.listdir
# <headingcell level=3>
# Imports
# <codecell>
import json
import os
import re
config = json.loads(open(config_fn).read())
# <headingcell level=2>
# Extraction
# <headingcell level=3>
# Read in the presentation MD
# <codecell>
mdfiles = flatten([sort([os.path.join(section["section"], x) for x in ls(section["section"])]) for section in config["sections"]])
addtwo = lambda x,y: x + y
md_concatenated = concatstrings([open(f).read() for f in mdfiles])
# <headingcell level=3>
# Remove SLIDE lines
# <codecell>
slide_pattern = r".*SLIDE.*"
md_out = concatstrings( re.split(slide_pattern, md_concatenated) )
# <headingcell level=3>
# Write to a file
# <codecell>
ohandle = open(outfile, "w")
ohandle.write(md_out)
ohandle.close()