blog/data_static/transform_md_to_csv.py
2020-07-13 11:54:16 +02:00

19 lines
555 B
Python

import os
import csv
def main():
with open('BlogPost.csv', 'w') as f:
bp_writer = csv.writer(f)
bp_writer.writerow(['created_dt', 'filename', 'title', 'body'])
for filename in os.listdir('blog_posts'):
with open(os.path.join('blog_posts', filename)) as f_bp:
created_dt = filename.split('_')[0]
title = f_bp.readline().split('# ')[1]
body = f_bp.read()
bp_writer.writerow([created_dt, filename, title, body])
if __name__ == "__main__":
main()