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
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