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
| #!/usr/bin/env python3 | |
| # | |
| # Get CSV from https://www.goodreads.com/review/import | |
| import csv | |
| import os | |
| # change these to match your setup | |
| outputdir = 'YOUROUTPUTDIRECTORY' | |
| goodreadsfile = '~/Downloads/goodreads_library_export.csv' | |
| goodreadsdict = csv.DictReader(open(goodreadsfile)) | |
| 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() | |
| # tagging author last name is too noisy | |
| #tags.append(row.pop('Author l-f').split(',')[0]) | |
| content = '''--- | |
| created: {} | |
| --- | |
| https://www.goodreads.com/book/show/{} | |
| Title: {} | |
| Author: {} | |
| Date Read: {} | |
| Tags: {} | |
| '''.format(row.pop('Date Added').replace('/', '-'), | |
| row.pop('Book Id'), | |
| row.pop('Title'), | |
| row.pop('Author'), | |
| row.pop('Date Read').replace('/', '-'), | |
| ' '.join(set(['#{}'.format(x) for x in tags]))) | |
| for k,v in row.items(): | |
| if v: | |
| if k == 'Bookshelves with positions': | |
| content += '{0}: {1}\n\n'.format(k,v.replace('#', '')) | |
| else: | |
| content += '{0}: {1}\n\n'.format(k,v) | |
| outfile = open(outfilepath, 'w') | |
| outfile.write(content.strip()) | |
| outfile.close() | |
| #break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment