Last active
January 18, 2025 15:31
-
-
Save cherihung/cc9b83bbbb2520276b1d664662eeebf5 to your computer and use it in GitHub Desktop.
convert each row in csv to a markdown file in python
This file contains hidden or 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
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
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.