Created
September 5, 2016 15:03
-
-
Save IuryAlves/5730f7bf2de9eb9204bb6ee889d3af6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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