-
-
Save Mootix1313/0b55e5043738caa1864b797b55867db9 to your computer and use it in GitHub Desktop.
This file contains 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
''' | |
source: https://gist.github.com/jag3773/c65afd53944815efe495dae798327021 | |
desc: refactored original import_goodreads.py to place a book's | |
meta-data in the frontmatter instead of the content area | |
''' | |
import csv | |
# change these to match your setup | |
OUTPUTDIR = './Reading/' | |
GOODREADSFILE = 'goodreads_library_export.csv' | |
with open(GOODREADSFILE,'r',encoding='utf-8') as fd: | |
goodreadsdict = csv.DictReader(fd) | |
for row in goodreadsdict: | |
pub_year = row['Year Published'] | |
if row['Original Publication Year']: | |
pub_year = row['Original Publication Year'] | |
OUTFILENAME = '-'.join([pub_year, row['Author l-f'], row['Title']]) | |
SANITIZEDNAME = ''.join([c for c in OUTFILENAME | |
if c.isalpha() or c.isdigit() or c in '.-_ ']).strip() | |
OUTFILEPATH = OUTPUTDIR + SANITIZEDNAME + '.md' | |
print(OUTFILEPATH) | |
# Set tags based on shelves and author lastname | |
tags = [] | |
for v in [row.pop('Exclusive Shelf'), row.pop('Bookshelves')]: | |
tags += v.replace(',', '').split() | |
# Setting up the frontmatter for the book entry | |
content= f''' | |
--- | |
tags: log/book | |
url: "https://www.goodreads.com/book/show/{row.pop('Book Id')}" | |
book-title: {row.pop('Title')} | |
book-author: {row.pop('Author')} | |
date-added: {row.pop('Date Added')} | |
date-read: {row.pop('Date Read').replace('/', '-')} | |
read-count: {row.pop('Read Count')} | |
book-tags: {' '.join(set([f'#{x}' for x in tags]))} | |
isbn: {row.pop("ISBN").replace("=","")} | |
isbn13: {row.pop("ISBN13").replace("=","")} | |
my-rating: {row.pop("My Rating")} | |
average-rating: {row.pop("Average Rating")} | |
publisher: {row.pop("Publisher")} | |
number-of-pages: {row.pop("Number of Pages")} | |
year-published: {row.pop("Year Published")} | |
original-publication-year: {row.pop("Original Publication Year")} | |
bookshelves-with-positions: {row.pop('Bookshelves with positions').replace('#', '')} | |
--- | |
''' | |
with open(OUTFILEPATH, 'w',encoding='utf-8') as outfile: | |
outfile.write(content.strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment