mirror of
https://github.com/satwikkansal/wtfpython.git
synced 2024-09-11 20:17:08 +03:00
Establish structure of simple parser to parse by category
This commit is contained in:
parent
491a98e478
commit
ca78a6d483
31
parse_readme.py
Normal file
31
parse_readme.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user