mirror of
https://github.com/satwikkansal/wtfpython
synced 2024-11-22 02:54:25 +01:00
Turn pseudo code to actual code
This commit is contained in:
parent
c979d82c1f
commit
67b7a5055a
@ -1,28 +1,56 @@
|
|||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
fname = "README.md"
|
fname = "README.md"
|
||||||
snipepts = []
|
snippets = []
|
||||||
|
|
||||||
with open(fname, 'r') as f:
|
with open(fname, 'r') as f:
|
||||||
lines = f.readlines()
|
lines = iter(f.readlines())
|
||||||
iterator
|
line = lines.next()
|
||||||
while iterator:
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
# check if it's a H3
|
# check if it's a H3
|
||||||
if line.startswith("###"):
|
if line.startswith("### "):
|
||||||
title = line.replace("### ", "")
|
title = line.replace("### ", "")
|
||||||
description = ''
|
# print(title, "found")
|
||||||
next_line = itertor.next
|
description = []
|
||||||
while not next_line.startswith("#### "):
|
next_line = lines.next()
|
||||||
|
|
||||||
# store lines till an H4 (explanation) is encountered
|
# store lines till an H4 (explanation) is encountered
|
||||||
|
while not next_line.startswith("#### "):
|
||||||
description.append(next_line)
|
description.append(next_line)
|
||||||
next_line = iterator.next
|
next_line = lines.next()
|
||||||
|
|
||||||
|
# print("Description captured", description[:10])
|
||||||
|
|
||||||
|
explanation = []
|
||||||
# store lines again until --- or another H3 is encountered
|
# store lines again until --- or another H3 is encountered
|
||||||
|
while not (next_line.startswith("---") or
|
||||||
|
next_line.startswith("### ")):
|
||||||
|
explanation.append(next_line)
|
||||||
|
next_line = lines.next()
|
||||||
|
|
||||||
|
# print("explanation captured", explanation[:10])
|
||||||
|
|
||||||
|
|
||||||
|
# Store the results finally
|
||||||
snippets.append({
|
snippets.append({
|
||||||
"title":,
|
"title": title,
|
||||||
"description":,
|
"description": '\n'.join(description),
|
||||||
"explanation":
|
"explanation": '\n'.join(explanation)
|
||||||
|
})
|
||||||
|
|
||||||
|
line = next_line
|
||||||
|
|
||||||
|
else:
|
||||||
|
line = lines.next()
|
||||||
|
|
||||||
|
except StopIteration:
|
||||||
|
snippets.append({
|
||||||
|
"title": title,
|
||||||
|
"description": '\n'.join(description),
|
||||||
|
"explanation": '\n'.join(explanation)
|
||||||
})
|
})
|
||||||
# repeat until EOL is encoutered
|
|
||||||
|
|
||||||
# separating by category
|
# separating by category
|
||||||
categories = ["a", "b", "c"]
|
categories = ["a", "b", "c"]
|
||||||
@ -33,4 +61,4 @@ for snip in snippets:
|
|||||||
cat = raw_input(snip["title"])
|
cat = raw_input(snip["title"])
|
||||||
snips_by_cat[cat].append(snip)
|
snips_by_cat[cat].append(snip)
|
||||||
|
|
||||||
pprint.pprint(snips_by_cat)
|
pprint.pprint("hail", snippets)
|
||||||
|
Loading…
Reference in New Issue
Block a user