本文整理汇总了Python中lazylibrarian.gr.GoodReads.find_book方法的典型用法代码示例。如果您正苦于以下问题:Python GoodReads.find_book方法的具体用法?Python GoodReads.find_book怎么用?Python GoodReads.find_book使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lazylibrarian.gr.GoodReads
的用法示例。
在下文中一共展示了GoodReads.find_book方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_book
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_book [as 别名]
def import_book(bookid, ebook=None, audio=None, wait=False):
""" search goodreads or googlebooks for a bookid and import the book
ebook/audio=None makes find_book use configured default """
if lazylibrarian.CONFIG['BOOK_API'] == "GoogleBooks":
GB = GoogleBooks(bookid)
if not wait:
_ = threading.Thread(target=GB.find_book, name='GB-IMPORT', args=[bookid, ebook, audio]).start()
else:
GB.find_book(bookid, ebook, audio)
else: # lazylibrarian.CONFIG['BOOK_API'] == "GoodReads":
GR = GoodReads(bookid)
if not wait:
_ = threading.Thread(target=GR.find_book, name='GR-IMPORT', args=[bookid, ebook, audio]).start()
else:
GR.find_book(bookid, ebook, audio)
示例2: grsync
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_book [as 别名]
def grsync(status, shelf):
# noinspection PyBroadException
try:
shelf = shelf.lower()
logger.info('Syncing %s to %s shelf' % (status, shelf))
myDB = database.DBConnection()
cmd = 'select bookid from books where status="%s"' % status
if status == 'Open':
cmd += ' or status="Have"'
results = myDB.select(cmd)
ll_list = []
for terms in results:
ll_list.append(terms['bookid'])
GA = grauth()
GR = None
shelves = GA.get_shelf_list()
found = False
for item in shelves: # type: dict
if item['name'] == shelf:
found = True
break
if not found:
res, msg = GA.create_shelf(shelf=shelf)
if not res:
logger.debug("Unable to create shelf %s: %s" % (shelf, msg))
return 0, 0
else:
logger.debug("Created new goodreads shelf: %s" % shelf)
gr_shelf = GA.get_gr_shelf_contents(shelf=shelf)
dstatus = status
if dstatus == "Open":
dstatus += "/Have"
logger.info("There are %s %s books, %s books on goodreads %s shelf" %
(len(ll_list), dstatus, len(gr_shelf), shelf))
# Sync method for WANTED:
# Get results of last_sync (if any)
# For each book in last_sync
# if not in ll_list, new deletion, remove from gr_shelf
# if not in gr_shelf, new deletion, remove from ll_list, mark Skipped
# For each book in ll_list
# if not in last_sync, new addition, add to gr_shelf
# For each book in gr_shelf
# if not in last sync, new addition, add to ll_list, mark Wanted
#
# save ll WANTED as last_sync
# For HAVE/OPEN method is the same, but only change status if HAVE, not OPEN
cmd = 'select SyncList from sync where UserID="%s" and Label="%s"' % ("goodreads", shelf)
res = myDB.match(cmd)
last_sync = []
shelf_changed = 0
ll_changed = 0
if res:
last_sync = getList(res['SyncList'])
added_to_shelf = list(set(gr_shelf) - set(last_sync))
removed_from_shelf = list(set(last_sync) - set(gr_shelf))
added_to_ll = list(set(ll_list) - set(last_sync))
removed_from_ll = list(set(last_sync) - set(ll_list))
logger.info("%s missing from lazylibrarian %s" % (len(removed_from_ll), shelf))
for book in removed_from_ll:
# first the deletions since last sync...
try:
res, content = GA.BookToList(book, shelf, action='remove')
except Exception as e:
logger.error("Error removing %s from %s: %s %s" % (book, shelf, type(e).__name__, str(e)))
res = None
content = ''
if res:
logger.debug("%10s removed from %s shelf" % (book, shelf))
shelf_changed += 1
else:
logger.warn("Failed to remove %s from %s shelf: %s" % (book, shelf, content))
logger.info("%s missing from goodreads %s" % (len(removed_from_shelf), shelf))
for book in removed_from_shelf:
# deleted from goodreads
cmd = 'select Status from books where BookID="%s"' % book
res = myDB.match(cmd)
if not res:
logger.debug('Adding new book %s to database' % book)
if not GR:
GR = GoodReads(book)
GR.find_book(book)
res = myDB.match(cmd)
if not res:
logger.warn('Book %s not found in database' % book)
else:
if res['Status'] in ['Have', 'Wanted']:
myDB.action('UPDATE books SET Status="Skipped" WHERE BookID=?', (book,))
ll_changed += 1
logger.debug("%10s set to Skipped" % book)
else:
logger.warn("Not removing %s, book is marked %s" % (book, res['Status']))
#.........这里部分代码省略.........
示例3: addBookToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_book [as 别名]
def addBookToDB(bookid, authorname):
type = 'book'
myDB = database.DBConnection()
GR = GoodReads(authorname, type)
# process book
dbbook = myDB.action('SELECT * from books WHERE BookID=?', [bookid]).fetchone()
controlValueDict = {"BookID": bookid}
if dbbook is None:
newValueDict = {
"BookID": "BookID: %s" % (bookid),
"Status": "Loading"
}
else:
newValueDict = {"Status": "Loading"}
myDB.upsert("books", newValueDict, controlValueDict)
book = GR.find_book()
if not book:
logger.warn("Error fetching bookinfo for BookID: " + bookid)
else:
controlValueDict = {"BookID": book['bookid']}
newValueDict = {
"AuthorName": book['authorname'],
"BookName": book['bookname'],
"BookDesc": book['bookdesc'],
"BookIsbn": book['bookisbn'],
"BookImg": book['bookimg'],
"BookLink": book['booklink'],
"BookRate": book['bookrate'],
"BookPages": book['bookpages'],
"BookDate": book['bookdate'],
"BookLang": book['booklang'],
"Status": "Skipped",
"BookAdded": formatter.today()
}
myDB.upsert("books", newValueDict, controlValueDict)
# process author
dbauthor = myDB.action("SELECT * from authors WHERE AuthorName='?'", [authorname]).fetchone()
controlValueDict = {"AuthorName": authorname}
if dbauthor is None:
newValueDict = {
"AuthorName": "Authorname: %s" % (authorname),
"Status": "Loading"
}
else:
newValueDict = {"Status": "Loading"}
author = GR.find_author_id()
if not author:
logger.warn("Error fetching authorinfo with name: " + authorname)
else:
controlValueDict = {"AuthorName": authorname}
newValueDict = {
"AuthorID": author['authorid'],
"AuthorLink": author['authorlink'],
"AuthorImg": author['authorimg'],
"AuthorBorn": author['authorborn'],
"AuthorDeath": author['authordeath'],
"DateAdded": formatter.today(),
"Status": "Loading"
}
myDB.upsert("authors", newValueDict, controlValueDict)