Skip to content

Instantly share code, notes, and snippets.

@IuryAlves
Created September 5, 2016 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IuryAlves/5730f7bf2de9eb9204bb6ee889d3af6b to your computer and use it in GitHub Desktop.
Save IuryAlves/5730f7bf2de9eb9204bb6ee889d3af6b to your computer and use it in GitHub Desktop.
# coding: utf-8
'''
Para rodar
python3 markdown_to_json.py file1 file2
'''
import json
import sys
def parse(text):
output = []
paragraphs = list(filter(lambda line: len(line.strip('\n\t')) > 0 , text.split('\n')))
output.append({
'room': {
'title': paragraphs[0],
'subtitle': paragraphs[1],
'excerpt': paragraphs[2],
'content': '\n'.join(paragraphs[3:])
}
})
return output
def main():
filenames = sys.argv[1:]
for filename in filenames:
with open(filename, encoding='utf8') as fp:
read = fp.read()
parsed = parse(read)
with open(filename + '.json', 'w', encoding='utf-8') as file_output:
json.dump(parsed, file_output, indent=4, ensure_ascii=False)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment