Skip to content

Instantly share code, notes, and snippets.

@cherihung
Last active April 20, 2022 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cherihung/cc9b83bbbb2520276b1d664662eeebf5 to your computer and use it in GitHub Desktop.
Save cherihung/cc9b83bbbb2520276b1d664662eeebf5 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))
@incognitozen
Copy link

if you get a issue with encoding, simply change
with open('file.csv', 'rb')
to
with open('file.csv', 'r')

as that first line reads the file in binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment