def _getAuthorImage(self, **kwargs): if 'id' not in kwargs: self.data = 'Missing parameter: name' return else: self.id = kwargs['id'] self.data = getAuthorImage(self.id)
def _getAuthorImage(self, **kwargs): if 'name' not in kwargs: self.data = 'Missing parameter: name' return else: self.id = kwargs['name'] self.data = getAuthorImage(self.name)
def _getAuthorImage(self, **kwargs): if 'id' not in kwargs: self.data = 'Missing parameter: id' return else: self.id = kwargs['id'] self.data = getAuthorImage(self.id)
def addAuthorToDB(authorname=None, refresh=False): myDB = database.DBConnection() GR = GoodReads(authorname) query = "SELECT * from authors WHERE AuthorName='%s'" % authorname.replace( "'", "''") dbauthor = myDB.match(query) controlValueDict = {"AuthorName": authorname} if dbauthor is None: newValueDict = { "AuthorID": "0: %s" % (authorname), "Status": "Loading" } logger.debug("Now adding new author: %s to database" % authorname) else: newValueDict = {"Status": "Loading"} logger.debug("Now updating author: %s" % authorname) myDB.upsert("authors", newValueDict, controlValueDict) author = GR.find_author_id(refresh=refresh) if author: authorid = author['authorid'] authorlink = author['authorlink'] authorimg = author['authorimg'] if 'nophoto' in authorimg: authorimg = getAuthorImage(authorid) if authorimg and authorimg.startswith('http'): newimg = cache_cover(authorid, authorimg) if newimg: authorimg = newimg controlValueDict = {"AuthorName": authorname} newValueDict = { "AuthorID": authorid, "AuthorLink": authorlink, "AuthorImg": authorimg, "AuthorBorn": author['authorborn'], "AuthorDeath": author['authordeath'], "DateAdded": today(), "Status": "Loading" } myDB.upsert("authors", newValueDict, controlValueDict) else: logger.warn(u"Nothing found for %s" % authorname) myDB.action('DELETE from authors WHERE AuthorName="%s"' % authorname) return # process books if lazylibrarian.BOOK_API == "GoogleBooks": book_api = GoogleBooks() book_api.get_author_books(authorid, authorname, refresh=refresh) elif lazylibrarian.BOOK_API == "GoodReads": GR.get_author_books(authorid, authorname, refresh=refresh) update_totals(authorid) logger.debug("[%s] Author update complete" % authorname)
def addAuthorToDB(authorname=None, refresh=False): myDB = database.DBConnection() GR = GoodReads(authorname) query = "SELECT * from authors WHERE AuthorName='%s'" % authorname.replace("'", "''") dbauthor = myDB.action(query).fetchone() controlValueDict = {"AuthorName": authorname} if dbauthor is None: newValueDict = { "AuthorID": "0: %s" % (authorname), "Status": "Loading" } logger.debug("Now adding new author: %s to database" % authorname) else: newValueDict = {"Status": "Loading"} logger.debug("Now updating author: %s" % authorname) myDB.upsert("authors", newValueDict, controlValueDict) author = GR.find_author_id(refresh=refresh) if author: authorid = author['authorid'] authorlink = author['authorlink'] authorimg = author['authorimg'] if 'nophoto' in authorimg: authorimg = getAuthorImage(authorid) if authorimg and authorimg.startswith('http'): newimg = cache_cover(authorid, authorimg) if newimg: authorimg = newimg controlValueDict = {"AuthorName": authorname} newValueDict = { "AuthorID": authorid, "AuthorLink": authorlink, "AuthorImg": authorimg, "AuthorBorn": author['authorborn'], "AuthorDeath": author['authordeath'], "DateAdded": today(), "Status": "Loading" } myDB.upsert("authors", newValueDict, controlValueDict) else: logger.warn(u"Nothing found for %s" % authorname) myDB.action('DELETE from authors WHERE AuthorName="%s"' % authorname) return # process books if lazylibrarian.BOOK_API == "GoogleBooks": book_api = GoogleBooks() book_api.get_author_books(authorid, authorname, refresh=refresh) elif lazylibrarian.BOOK_API == "GoodReads": GR.get_author_books(authorid, authorname, refresh=refresh) update_totals(authorid) logger.debug("[%s] Author update complete" % authorname)
def addAuthorToDB(authorname=None, refresh=False, authorid=None, addbooks=True): """ Add an author to the database by name or id, and optionally get a list of all their books If author already exists in database, refresh their details and optionally booklist """ threadname = threading.currentThread().name if "Thread-" in threadname: threading.currentThread().name = "AddAuthorToDB" try: myDB = database.DBConnection() match = False authorimg = '' new_author = not refresh if authorid: controlValueDict = {"AuthorID": authorid} newValueDict = {"Status": "Loading"} dbauthor = myDB.match("SELECT * from authors WHERE AuthorID='%s'" % authorid) if not dbauthor: authorname = 'unknown author' logger.debug("Now adding new author id: %s to database" % authorid) new_author = True else: authorname = dbauthor['authorname'] logger.debug("Now updating author %s " % authorname) new_author = False myDB.upsert("authors", newValueDict, controlValueDict) GR = GoodReads(authorname) author = GR.get_author_info(authorid=authorid) if author: authorname = author['authorname'] authorimg = author['authorimg'] controlValueDict = {"AuthorID": authorid} newValueDict = { "AuthorLink": author['authorlink'], "DateAdded": today() } if not dbauthor or (dbauthor and not dbauthor['manual']): newValueDict["AuthorName"] = author['authorname'] newValueDict["AuthorImg"] = author['authorimg'] newValueDict["AuthorBorn"] = author['authorborn'] newValueDict["AuthorDeath"] = author['authordeath'] myDB.upsert("authors", newValueDict, controlValueDict) match = True else: logger.warn(u"Nothing found for %s" % authorid) if not dbauthor: myDB.action('DELETE from authors WHERE AuthorID="%s"' % authorid) if authorname and not match: authorname = ' '.join( authorname.split()) # ensure no extra whitespace GR = GoodReads(authorname) query = "SELECT * from authors WHERE AuthorName='%s'" % authorname.replace( "'", "''") dbauthor = myDB.match(query) controlValueDict = {"AuthorName": authorname} if not dbauthor: newValueDict = { "AuthorID": "0: %s" % authorname, "Status": "Loading" } logger.debug("Now adding new author: %s to database" % authorname) new_author = True else: newValueDict = {"Status": "Loading"} logger.debug("Now updating author: %s" % authorname) new_author = False myDB.upsert("authors", newValueDict, controlValueDict) author = GR.find_author_id(refresh=refresh) if author: authorid = author['authorid'] authorimg = author['authorimg'] controlValueDict = {"AuthorName": authorname} newValueDict = { "AuthorID": author['authorid'], "AuthorLink": author['authorlink'], "DateAdded": today(), "Status": "Loading" } if not dbauthor or (dbauthor and not dbauthor['manual']): newValueDict["AuthorImg"] = author['authorimg'] newValueDict["AuthorBorn"] = author['authorborn'] newValueDict["AuthorDeath"] = author['authordeath'] myDB.upsert("authors", newValueDict, controlValueDict) match = True else: logger.warn(u"Nothing found for %s" % authorname) if not dbauthor: myDB.action('DELETE from authors WHERE AuthorName="%s"' % authorname) return if not match: logger.error( "AddAuthorToDB: No matching result for authorname or authorid") return # if author is set to manual, should we allow replacing 'nophoto' ? new_img = False match = myDB.match("SELECT Manual from authors WHERE AuthorID='%s'" % authorid) if not match or not match['Manual']: if authorimg and 'nophoto' in authorimg: newimg = getAuthorImage(authorid) if newimg: authorimg = newimg new_img = True # allow caching if authorimg and authorimg.startswith('http'): newimg, success = cache_img("author", authorid, authorimg, refresh=refresh) if success: authorimg = newimg new_img = True else: logger.debug('Failed to cache image for %s' % authorimg) if new_img: controlValueDict = {"AuthorID": authorid} newValueDict = {"AuthorImg": authorimg} myDB.upsert("authors", newValueDict, controlValueDict) if addbooks: if new_author: bookstatus = lazylibrarian.CONFIG['NEWAUTHOR_STATUS'] else: bookstatus = lazylibrarian.CONFIG['NEWBOOK_STATUS'] # process books if lazylibrarian.CONFIG['BOOK_API'] == "GoogleBooks": book_api = GoogleBooks() book_api.get_author_books(authorid, authorname, bookstatus, refresh=refresh) elif lazylibrarian.CONFIG['BOOK_API'] == "GoodReads": GR = GoodReads(authorname) GR.get_author_books(authorid, authorname, bookstatus, refresh=refresh) # update totals works for existing authors only. # New authors need their totals updating after libraryscan or import of books. if not new_author: update_totals(authorid) else: # if we're not loading any books, mark author as ignored controlValueDict = {"AuthorID": authorid} newValueDict = {"Status": "Ignored"} myDB.upsert("authors", newValueDict, controlValueDict) msg = "[%s] Author update complete" % authorname logger.debug(msg) return msg except Exception: msg = 'Unhandled exception in addAuthorToDB: %s' % traceback.format_exc( ) logger.error(msg) return msg
def addAuthorToDB(authorname=None, refresh=False, authorid=None, addbooks=True): """ Add an author to the database by name or id, and optionally get a list of all their books If author already exists in database, refresh their details and optionally booklist """ threadname = threading.currentThread().name if "Thread-" in threadname: threading.currentThread().name = "AddAuthorToDB" try: myDB = database.DBConnection() match = False authorimg = '' new_author = not refresh entry_status = '' if authorid: dbauthor = myDB.match("SELECT * from authors WHERE AuthorID=?", (authorid, )) if not dbauthor: authorname = 'unknown author' logger.debug("Adding new author id %s to database" % authorid) new_author = True else: entry_status = dbauthor['Status'] authorname = dbauthor['authorname'] logger.debug("Updating author %s " % authorname) new_author = False controlValueDict = {"AuthorID": authorid} newValueDict = {"Status": "Loading"} myDB.upsert("authors", newValueDict, controlValueDict) GR = GoodReads(authorname) author = GR.get_author_info(authorid=authorid) if author: authorname = author['authorname'] authorimg = author['authorimg'] controlValueDict = {"AuthorID": authorid} newValueDict = { "AuthorLink": author['authorlink'], "DateAdded": today() } if not dbauthor or (dbauthor and not dbauthor['manual']): newValueDict["AuthorName"] = author['authorname'] newValueDict["AuthorImg"] = author['authorimg'] newValueDict["AuthorBorn"] = author['authorborn'] newValueDict["AuthorDeath"] = author['authordeath'] myDB.upsert("authors", newValueDict, controlValueDict) match = True else: logger.warn(u"Nothing found for %s" % authorid) if not dbauthor: myDB.action('DELETE from authors WHERE AuthorID=?', (authorid, )) if authorname and not match: authorname = ' '.join( authorname.split()) # ensure no extra whitespace GR = GoodReads(authorname) author = GR.find_author_id(refresh=refresh) query = "SELECT * from authors WHERE AuthorName=?" dbauthor = myDB.match(query, (authorname.replace("'", "''"), )) if author and not dbauthor: # may have different name for same authorid (spelling?) query = "SELECT * from authors WHERE AuthorID=?" dbauthor = myDB.match(query, (author['authorid'], )) authorname = dbauthor['AuthorName'] controlValueDict = {"AuthorName": authorname} if not dbauthor: newValueDict = { "AuthorID": "0: %s" % authorname, "Status": "Loading" } logger.debug("Now adding new author: %s to database" % authorname) entry_status = lazylibrarian.CONFIG['NEWAUTHOR_STATUS'] new_author = True else: newValueDict = {"Status": "Loading"} logger.debug("Now updating author: %s" % authorname) entry_status = dbauthor['Status'] new_author = False myDB.upsert("authors", newValueDict, controlValueDict) if author: authorid = author['authorid'] authorimg = author['authorimg'] controlValueDict = {"AuthorName": authorname} newValueDict = { "AuthorID": author['authorid'], "AuthorLink": author['authorlink'], "DateAdded": today(), "Status": "Loading" } if not dbauthor or (dbauthor and not dbauthor['manual']): newValueDict["AuthorImg"] = author['authorimg'] newValueDict["AuthorBorn"] = author['authorborn'] newValueDict["AuthorDeath"] = author['authordeath'] myDB.upsert("authors", newValueDict, controlValueDict) match = True else: logger.warn(u"Nothing found for %s" % authorname) if not dbauthor: myDB.action('DELETE from authors WHERE AuthorName=?', (authorname, )) return if not match: logger.error( "AddAuthorToDB: No matching result for authorname or authorid") return # if author is set to manual, should we allow replacing 'nophoto' ? new_img = False match = myDB.match("SELECT Manual from authors WHERE AuthorID=?", (authorid, )) if not match or not match['Manual']: if authorimg and 'nophoto' in authorimg: newimg = getAuthorImage(authorid) if newimg: authorimg = newimg new_img = True # allow caching if authorimg and authorimg.startswith('http'): newimg, success = cache_img("author", authorid, authorimg, refresh=refresh) if success: authorimg = newimg new_img = True else: logger.debug('Failed to cache image for %s' % authorimg) if new_img: controlValueDict = {"AuthorID": authorid} newValueDict = {"AuthorImg": authorimg} myDB.upsert("authors", newValueDict, controlValueDict) if addbooks: # audiostatus = lazylibrarian.CONFIG['NEWAUDIO_STATUS'] if new_author: bookstatus = lazylibrarian.CONFIG['NEWAUTHOR_STATUS'] else: bookstatus = lazylibrarian.CONFIG['NEWBOOK_STATUS'] if entry_status not in ['Active', 'Wanted', 'Ignored', 'Paused']: entry_status = 'Active' # default for invalid/unknown or "loading" # process books if lazylibrarian.CONFIG['BOOK_API'] == "GoogleBooks": book_api = GoogleBooks() book_api.get_author_books(authorid, authorname, bookstatus, entrystatus=entry_status, refresh=refresh) elif lazylibrarian.CONFIG['BOOK_API'] == "GoodReads": book_api = GoodReads(authorname) book_api.get_author_books(authorid, authorname, bookstatus, entrystatus=entry_status, refresh=refresh) # update totals works for existing authors only. # New authors need their totals updating after libraryscan or import of books. if not new_author: update_totals(authorid) if new_author and lazylibrarian.CONFIG['GR_FOLLOWNEW']: res = grfollow(authorid, True) if res.startswith('Unable'): logger.warn(res) try: followid = res.split("followid=")[1] logger.debug('%s marked followed' % authorname) except IndexError: followid = '' myDB.action('UPDATE authors SET GRfollow=? WHERE AuthorID=?', (followid, authorid)) else: # if we're not loading any books, mark author as ignored entry_status = 'Ignored' controlValueDict = {"AuthorID": authorid} newValueDict = {"Status": entry_status} myDB.upsert("authors", newValueDict, controlValueDict) msg = "[%s] Author update complete, status %s" % (authorname, entry_status) logger.info(msg) return msg except Exception: msg = 'Unhandled exception in addAuthorToDB: %s' % traceback.format_exc( ) logger.error(msg) return msg
def addAuthorToDB(authorname=None, refresh=False): """ Add an author to the database, and get list of all their books If author already exists in database, refresh their details and booklist """ try: myDB = database.DBConnection() GR = GoodReads(authorname) query = "SELECT * from authors WHERE AuthorName='%s'" % authorname.replace("'", "''") dbauthor = myDB.match(query) controlValueDict = {"AuthorName": authorname} if not dbauthor: newValueDict = { "AuthorID": "0: %s" % (authorname), "Status": "Loading" } logger.debug("Now adding new author: %s to database" % authorname) else: newValueDict = {"Status": "Loading"} logger.debug("Now updating author: %s" % authorname) myDB.upsert("authors", newValueDict, controlValueDict) author = GR.find_author_id(refresh=refresh) if author: authorid = author['authorid'] authorlink = author['authorlink'] authorimg = author['authorimg'] controlValueDict = {"AuthorName": authorname} newValueDict = { "AuthorID": authorid, "AuthorLink": authorlink, "AuthorImg": authorimg, "AuthorBorn": author['authorborn'], "AuthorDeath": author['authordeath'], "DateAdded": today(), "Status": "Loading" } myDB.upsert("authors", newValueDict, controlValueDict) else: logger.warn(u"Nothing found for %s" % authorname) myDB.action('DELETE from authors WHERE AuthorName="%s"' % authorname) return new_img = False if authorimg and 'nophoto' in authorimg: authorimg = getAuthorImage(authorid) new_img = True if authorimg and authorimg.startswith('http'): newimg = cache_cover(authorid, authorimg) if newimg: authorimg = newimg new_img = True if new_img: controlValueDict = {"AuthorID": authorid} newValueDict = {"AuthorImg": authorimg} myDB.upsert("authors", newValueDict, controlValueDict) # process books if lazylibrarian.BOOK_API == "GoogleBooks": book_api = GoogleBooks() book_api.get_author_books(authorid, authorname, refresh=refresh) elif lazylibrarian.BOOK_API == "GoodReads": GR.get_author_books(authorid, authorname, refresh=refresh) # update totals works for existing authors only. # New authors need their totals updating after libraryscan or import of books. if dbauthor: update_totals(authorid) logger.debug("[%s] Author update complete" % authorname) except Exception as e: logger.error('Unhandled exception in addAuthorToDB: %s' % traceback.format_exc())