Skip to content

Instantly share code, notes, and snippets.

@kellbot
Created October 25, 2021 04:32
Show Gist options
  • Save kellbot/674a99368fa9beb93aa0e314d32014b4 to your computer and use it in GitHub Desktop.
Save kellbot/674a99368fa9beb93aa0e314d32014b4 to your computer and use it in GitHub Desktop.
import subprocess
from urllib.request import urlopen
from xml.etree.ElementTree import parse
goodreads_id = [your goodreads id here]
goodreads_api_key = [your api key here]
calibre_server = [server url e.g. http://localhost:8080/#calibre-library or path to library]
calibre_username = [your calibre username]
calibre_password = [your calibre password]
new_tag = [desired tag to add]
var_url = urlopen('https://www.goodreads.com/review/list/'+goodreads_id+'.xml?key='+goodreads-api_key+'&v=2&shelf=to-read&per_page=200&page=1')
xmldoc = parse(var_url)
for item in xmldoc.iterfind('reviews/review/book'):
goodreads_id = item.findtext('id')
temp = subprocess.run("calibredb list --with-library "+ calibre_server +" --username="+ calibre_username +" --password="+ calibre_password +" -s identifiers:=goodreads:" + goodreads_id + " --fields id --separator ':'", shell=True, stdout=subprocess.PIPE, universal_newlines=True)
output = temp.stdout
output = output.split('\n')
if len(output) > 2:
subprocess.run("calibredb set_metadata --with-library "+ calibre_server +" --username="+ calibre_username +" --password="+ calibre_password +" "+output[1]+" --field tags:"+new_tag+", shell=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment