Skip to content

Commit ca78a6d

Browse files
committed
Establish structure of simple parser to parse by category
1 parent 491a98e commit ca78a6d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

parse_readme.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pprint
2+
3+
fname = "README.md"
4+
snipepts = []
5+
6+
with open(fname, 'r') as f:
7+
lines = f.readlines()
8+
for line in lines:
9+
# check if it's a H3
10+
if line.startswith("###"):
11+
title = line.replace("### ", "")
12+
# get Title, des
13+
# store lines till an H4 (explanation) is encountered
14+
# store lines again until --- or another H3 is encountered
15+
snippets.append({
16+
"title":,
17+
"description":,
18+
"explanation":
19+
})
20+
# repeat until EOL is encoutered
21+
22+
# separating by category
23+
categories = ["a", "b", "c"]
24+
25+
snips_by_cat = {k:[] for k in categories}
26+
27+
for snip in snippets:
28+
cat = raw_input(snip["title"])
29+
snips_by_cat[cat].append(snip)
30+
31+
pprint.pprint(snips_by_cat)

0 commit comments

Comments
 (0)