Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Last active June 14, 2021 03:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarmitage/8ea7f4eb63d73a5ac7a1285781c8b093 to your computer and use it in GitHub Desktop.
Save jarmitage/8ea7f4eb63d73a5ac7a1285781c8b093 to your computer and use it in GitHub Desktop.
Convert Calibre Library to Roam Research bullets

Convert Calibre Library to Roam Research bullets

Calibre>Convert books>Create a catalogue of the books in your library

Output examples:

  • [[Structure and Interpretation of Classical Mechanics]] by [[Gerald Jay Sussman]], [[Jack Wisdom]] is about #[[Mechanical Engineering]], #Science, and was published by [[MIT Press]] in #2015.
  • [[Mindstorms: Children, Computers, and Powerful Ideas]] by [[Seymour A. Papert]] is about #Education, and was published by [[Basic Books]] in #1993.
  • [[You and Your Research]] by [[Richard W. Hamming]] is about #Learning, #Research, and was published by [[Bell Communications Research]] in #1986.
  • [[Rhythm and Transforms]] by [[William Arthur Sethares]] is about #Music, and was published by [[Springer]] in #2007.
  • [[The Structure of Scientific Revolutions]] by [[Thomas S. Kuhn]] is about #[[History of Science]], #Science, #Philosophy, and was published by [[University of Chicago Press]] in #1996.
import pandas as pd
def stateBook(b):
return fmtTitle(b['title']) + fmtAuthors(b['authors']) + fmtTags(b['tags']) \
+ fmtPubAndDate(b['publisher'], b['pubdate']) + '.'
def fmtAuthors(authors):
return ' by ' + (', ').join(['[['+a+']]' for a in authors.split(' & ')])
def fmtTags(tags):
tags = str(tags).split(', ')
tmp = []
for t in tags:
if ' ' in t:
tmp.append('#[['+t+']]')
else:
tmp.append('#'+t)
return ' is about ' + (', ').join(tmp)
def fmtTitle(titles):
return '[['+titles+']]'
def fmtPubAndDate(publisher, date):
tmp = ''
if pd.isna(publisher):
if int(date[0]) is not 0:
tmp = ', and was published in #' + date[:4]
else:
tmp = ', and was published by ' + '[['+str(publisher)+']]'
if date[0] is not 0:
tmp += ' in #' + date[:4]
return tmp
lib = pd.read_csv('./CalibreLibrary.csv')
roam = pd.Series(lib.apply(stateBook, axis=1))
f = open('./RoamBullets.txt', 'w+')
[f.write(r+'\n') for r in roam]
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment