Skip to content

Instantly share code, notes, and snippets.

@nfway
Forked from cherihung/csv-to-mkdown-files.py
Created March 16, 2021 01:48
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 nfway/72f8b1fb62232702f5335c05902100ee to your computer and use it in GitHub Desktop.
Save nfway/72f8b1fb62232702f5335c05902100ee to your computer and use it in GitHub Desktop.
convert each row in csv to a markdown file in python
import csv
def toMarkdown(item):
newTemp = "---"+"\n"+"layout: sculpture"+"\n"+"pageId: "+item[0]+"\n"+"uid: "+item[1]+"\n"
newTemp += "title: "+item[2]+"\n"+"location: "+item[3]+"\n"+"completionDate: "+item[4]+"\n"
newTemp += "description: "+item[5]+"\n"+"imageId: "+item[6]+"\n"
newTemp += "---"+"\n"
return newTemp
with open('file.csv', 'rb') as f:
reader = csv.reader(f, delimiter='|', quoting=csv.QUOTE_NONE)
for row in reader:
with open('temp/o' + str(row[0]) + '.md', 'w') as output:
output.write(toMarkdown(row))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment