Skip to content

Instantly share code, notes, and snippets.

@clokep
Last active March 3, 2016 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clokep/3cd04b72a1901376e088 to your computer and use it in GitHub Desktop.
Save clokep/3cd04b72a1901376e088 to your computer and use it in GitHub Desktop.
Python script to convert an exported Libib (http://www.libib.com/) CSV to a format that goodreads (https://www.goodreads.com/) can import
# Copyright (c) 2016, Patrick Cloke
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
import csv
def map_row(row):
"""
Map from a libib row to a GoodReads row.
libib format:
authors,first_name,last_name,title,description,rating,review_date,
review,status,began_date,completed_date,tags,notes,groups,copies,
added_date,publisher,publish_date,pages,asin,isbn10,isbn13
GoodReads format:
Title, Author, ISBN, My Rating, Average Rating, Publisher, Binding,
Year Published, Original Publication Year, Date Read, Date Added,
Bookshelves, My Review
"""
new_indices = [3, -1, 20, 5, -1, 16, -1, -1, -1, 10, 15, 11, 7]
new_row = []
for i in new_indices:
if i < 0:
value = ''
else:
value = row[i]
# GoodReads only supports integer ratings.
if i == 5 and value:
value = str(int(float(value)))
new_row.append(value)
return new_row
with open('data.csv', 'r') as f:
reader = csv.reader(f)
with open('data-out.csv', 'w') as fout:
headers = next(reader)
new_headers = (
'Title, Author, ISBN, My Rating, Average Rating, Publisher, '
'Binding, Year Published, Original Publication Year, Date Read, '
'Date Added, Bookshelves, My Review'
)
fout.write(new_headers + '\n')
for row in reader:
new_row = map_row(row)
fout.write(', '.join(new_row) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment