Sha256: f1cd4ee906438551ca377bc513000a8d1a06a71688d159e4ff70802e6bbb083e

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

import pandas as pd

from slugify import slugify

# Create a dataFrame from csv file
data = pd.read_csv("../_data/books.csv", sep=',', engine ='python', encoding="utf-8").fillna('')

# Set the titles column to a list
books = data.values.tolist()

# Loop through each name, create .md file, set contents to string
for book in books:
	author2 =str(book[18])# str is a function
	author3 =str(book[22])	
	# the next lines create the different components of the url for the main author
	author_raw = str(book[14])
	author_split = author_raw.split(" ") # split is a built-in method, we are transforming the full name of the author into a list
	author_short = (author_split[-3:])
	author = "-".join(author_short)
	# the next lines create the different components of the url for the title
	title_raw = str(book[0]) 
	title_split = title_raw.split(" ")
	title_short = (title_split[:4])
	title = "-".join(title_short)

	year = str(book[3])

	url_raw = title+"-"+author+"-"+year
	
	url = slugify(url_raw) # slugify is an imported app


	file_name = f'{url}.md'	
	xcrpt = str(book[9])


	with open(file_name, 'w', encoding="utf-8") as f:
		f.write(f'---\ntitle: {title_raw}\nauthor: {author_raw}\nauthor2: {author2}\nauthor3: {author3}\n---\n{xcrpt}')
		f.close()
	print(f'{file_name} saved')

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
morel-theme-0.1.3 assets/---copy-content-to-main-folder---/_books/csv-to-md.py