From ca78a6d4836a5fdb81e5f48e0b6c72b902961402 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Wed, 17 Jan 2018 18:24:00 +0530 Subject: [PATCH] Establish structure of simple parser to parse by category --- parse_readme.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 parse_readme.py diff --git a/parse_readme.py b/parse_readme.py new file mode 100644 index 0000000..b8690ef --- /dev/null +++ b/parse_readme.py @@ -0,0 +1,31 @@ +import pprint + +fname = "README.md" +snipepts = [] + +with open(fname, 'r') as f: + lines = f.readlines() + for line in lines: + # check if it's a H3 + if line.startswith("###"): + title = line.replace("### ", "") + # get Title, des + # store lines till an H4 (explanation) is encountered + # store lines again until --- or another H3 is encountered + snippets.append({ + "title":, + "description":, + "explanation": + }) + # repeat until EOL is encoutered + +# separating by category +categories = ["a", "b", "c"] + +snips_by_cat = {k:[] for k in categories} + +for snip in snippets: + cat = raw_input(snip["title"]) + snips_by_cat[cat].append(snip) + +pprint.pprint(snips_by_cat)