本文整理汇总了Python中lazylibrarian.gr.GoodReads.find_author_id方法的典型用法代码示例。如果您正苦于以下问题:Python GoodReads.find_author_id方法的具体用法?Python GoodReads.find_author_id怎么用?Python GoodReads.find_author_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lazylibrarian.gr.GoodReads
的用法示例。
在下文中一共展示了GoodReads.find_author_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorToDB(authorname=None):
threading.currentThread().name = "DBIMPORT"
type = 'author'
myDB = database.DBConnection()
GR = GoodReads(authorname, type)
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"
}
else:
newValueDict = {"Status": "Loading"}
myDB.upsert("authors", newValueDict, controlValueDict)
author = GR.find_author_id()
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": formatter.today(),
"Status": "Loading"
}
myDB.upsert("authors", newValueDict, controlValueDict)
else:
logger.error("Nothing found")
# process books
GR.get_author_books(authorid)
lastbook = myDB.action("SELECT BookName, BookLink, BookDate from books WHERE AuthorID='%s' order by BookDate DESC" % authorid).fetchone()
bookCount = myDB.select("SELECT COUNT(BookName) as counter FROM books WHERE AuthorID='%s'" % authorid)
for count in bookCount:
controlValueDict = {"AuthorID": authorid}
newValueDict = {
"Status": "Active",
"TotalBooks": count['counter'],
"LastBook": lastbook['BookName'],
"LastLink": lastbook['BookLink'],
"LastDate": lastbook['BookDate']
}
myDB.upsert("authors", newValueDict, controlValueDict)
logger.info("Processing complete: Added %s books to the database" % str(count['counter']))
示例2: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
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)
示例3: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorToDB(authorname=None, refresh=False):
threading.currentThread().name = "DBIMPORT"
#type = 'author'
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.info("Now adding new author: %s to database" % authorname)
else:
newValueDict = {"Status": "Loading"}
logger.info("Now updating author: %s" % authorname)
myDB.upsert("authors", newValueDict, controlValueDict)
author = GR.find_author_id()
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": formatter.today(),
"Status": "Loading"
}
myDB.upsert("authors", newValueDict, controlValueDict)
else:
logger.error("Nothing found")
# 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)
logger.info("[%s] Author update complete" % authorname)
示例4: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorToDB(authorname=None):
threading.currentThread().name = "DBIMPORT"
type = 'author'
myDB = database.DBConnection()
GR = GoodReads(authorname, type)
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"
}
else:
newValueDict = {"Status": "Loading"}
myDB.upsert("authors", newValueDict, controlValueDict)
author = GR.find_author_id()
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": formatter.today(),
"Status": "Loading"
}
myDB.upsert("authors", newValueDict, controlValueDict)
else:
logger.error("Nothing found")
# process books
GR.get_author_books(authorid)
示例5: addAuthorNameToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorNameToDB(author=None, refresh=False, addbooks=True):
# get authors name in a consistent format, look them up in the database
# if not in database, try to import them.
# return authorname,authorid,new where new=False if author already in db, new=True if added
# authorname returned is our preferred name, or empty string if not found or unable to add
new = False
if not author or len(author) < 2:
logger.debug('Invalid Author Name [%s]' % author)
return "", "", False
author = formatAuthorName(author)
myDB = database.DBConnection()
# Check if the author exists, and import the author if not,
check_exist_author = myDB.match('SELECT AuthorID FROM authors where AuthorName=?', (author,))
# If no exact match, look for a close fuzzy match to handle misspellings, accents
if not check_exist_author:
match_name = author.lower()
res = myDB.action('select AuthorID,AuthorName from authors')
for item in res:
aname = item['AuthorName']
if aname:
match_fuzz = fuzz.ratio(aname.lower(), match_name)
if match_fuzz >= 95:
logger.debug("Fuzzy match [%s] %s%% for [%s]" % (item['AuthorName'], match_fuzz, author))
check_exist_author = item
author = item['AuthorName']
break
if not check_exist_author and lazylibrarian.CONFIG['ADD_AUTHOR']:
logger.debug('Author %s not found in database, trying to add' % author)
# no match for supplied author, but we're allowed to add new ones
GR = GoodReads(author)
try:
author_gr = GR.find_author_id()
except Exception as e:
logger.warn("%s finding author id for [%s] %s" % (type(e).__name__, author, str(e)))
return "", "", False
# only try to add if GR data matches found author data
if author_gr:
authorname = author_gr['authorname']
# authorid = author_gr['authorid']
# "J.R.R. Tolkien" is the same person as "J. R. R. Tolkien" and "J R R Tolkien"
match_auth = author.replace('.', ' ')
match_auth = ' '.join(match_auth.split())
match_name = authorname.replace('.', ' ')
match_name = ' '.join(match_name.split())
match_name = unaccented(match_name)
match_auth = unaccented(match_auth)
# allow a degree of fuzziness to cater for different accented character handling.
# some author names have accents,
# filename may have the accented or un-accented version of the character
# The currently non-configurable value of fuzziness might need to go in config
# We stored GoodReads unmodified author name in
# author_gr, so store in LL db under that
# fuzz.ratio doesn't lowercase for us
match_fuzz = fuzz.ratio(match_auth.lower(), match_name.lower())
if match_fuzz < 90:
logger.debug("Failed to match author [%s] to authorname [%s] fuzz [%d]" %
(author, match_name, match_fuzz))
# To save loading hundreds of books by unknown authors at GR or GB, ignore unknown
if (author != "Unknown") and (match_fuzz >= 90):
# use "intact" name for author that we stored in
# GR author_dict, not one of the various mangled versions
# otherwise the books appear to be by a different author!
author = author_gr['authorname']
authorid = author_gr['authorid']
# this new authorname may already be in the
# database, so check again
check_exist_author = myDB.match('SELECT AuthorID FROM authors where AuthorID=?', (authorid,))
if check_exist_author:
logger.debug('Found goodreads authorname %s in database' % author)
else:
logger.info("Adding new author [%s]" % author)
try:
addAuthorToDB(authorname=author, refresh=refresh, authorid=authorid, addbooks=addbooks)
check_exist_author = myDB.match('SELECT AuthorID FROM authors where AuthorID=?', (authorid,))
if check_exist_author:
new = True
except Exception as e:
logger.error('Failed to add author [%s] to db: %s %s' % (author, type(e).__name__, str(e)))
# check author exists in db, either newly loaded or already there
if not check_exist_author:
logger.debug("Failed to match author [%s] in database" % author)
return "", "", False
author = makeUnicode(author)
return author, check_exist_author['AuthorID'], new
示例6: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorToDB(authorname=None, refresh=False):
threading.currentThread().name = "DBIMPORT"
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']
controlValueDict = {"AuthorName": authorname}
newValueDict = {
"AuthorID": authorid,
"AuthorLink": authorlink,
"AuthorImg": authorimg,
"AuthorBorn": author['authorborn'],
"AuthorDeath": author['authordeath'],
"DateAdded": formatter.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)
havebooks = myDB.action(
'SELECT count("BookID") as counter from books WHERE AuthorName="%s" AND (Status="Have" OR Status="Open")' %
authorname).fetchone()
myDB.action('UPDATE authors set HaveBooks="%s" where AuthorName="%s"' % (havebooks['counter'], authorname))
totalbooks = myDB.action(
'SELECT count("BookID") as counter FROM books WHERE AuthorName="%s"' % authorname).fetchone()
myDB.action('UPDATE authors set TotalBooks="%s" where AuthorName="%s"' % (totalbooks['counter'], authorname))
unignoredbooks = myDB.action(
'SELECT count("BookID") as counter FROM books WHERE AuthorName="%s" AND Status!="Ignored"' %
authorname).fetchone()
myDB.action('UPDATE authors set UnignoredBooks="%s" where AuthorName="%s"' % (unignoredbooks['counter'], authorname))
logger.debug("[%s] Author update complete" % authorname)
示例7: find_book
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def find_book(self, bookid=None, queue=None):
threading.currentThread().name = "GB-ADD-BOOK"
myDB = database.DBConnection()
URL = 'https://www.googleapis.com/books/v1/volumes/' + str(bookid) + "?key="+lazylibrarian.GB_API
jsonresults = json.JSONDecoder().decode(urllib2.urlopen(URL, timeout=30).read())
# Darkie67:
# replacing German Umlauts and filtering out ":"
#
booknamealt = jsonresults['volumeInfo']['title']
booknametmp1=booknamealt.replace(u'\xf6',u'oe')
booknametmp2=booknametmp1.replace(u'\xe4',u'ae')
booknametmp3=booknametmp2.replace(u'\xdf',u'ss')
booknametmp4=booknametmp3.replace(u'\xc4',u'Ae')
booknametmp5=booknametmp4.replace(u'\xdc',u'Ue')
booknametmp6=booknametmp5.replace(u'\xd6',u'Oe')
booknametmp7=booknametmp6.replace(':','')
bookname=booknametmp7.replace(u'\xfc',u'ue')
# Darkie67 end
try:
authorname = jsonresults['volumeInfo']['authors'][0]
except KeyError:
logger.debug('Book %s does not contain author field' % bookname)
try:
#skip if language is in ignore list
booklang = jsonresults['volumeInfo']['language']
valid_langs = ([valid_lang.strip() for valid_lang in lazylibrarian.IMP_PREFLANG.split(',')])
if booklang not in valid_langs:
logger.debug('Book %s language does not match preference' % bookname)
except KeyError:
logger.debug('Book does not have language field')
try:
bookpub = jsonresults['volumeInfo']['publisher']
except KeyError:
bookpub = None
try:
booksub = jsonresults['volumeInfo']['subtitle']
except KeyError:
booksub = None
try:
bookdate = jsonresults['volumeInfo']['publishedDate']
except KeyError:
bookdate = '0000-00-00'
try:
bookimg = jsonresults['volumeInfo']['imageLinks']['thumbnail']
except KeyError:
bookimg = 'images/nocover.png'
try:
bookrate = jsonresults['volumeInfo']['averageRating']
except KeyError:
bookrate = 0
try:
bookpages = jsonresults['volumeInfo']['pageCount']
except KeyError:
bookpages = 0
try:
bookgenre = jsonresults['volumeInfo']['categories'][0]
except KeyError:
bookgenre = None
try:
bookdesc = jsonresults['volumeInfo']['description']
except KeyError:
bookdesc = None
try:
if jsonresults['volumeInfo']['industryIdentifiers'][0]['type'] == 'ISBN_10':
bookisbn = jsonresults['volumeInfo']['industryIdentifiers'][0]['identifier']
else:
bookisbn = None
except KeyError:
bookisbn = None
booklink = jsonresults['volumeInfo']['canonicalVolumeLink']
bookrate = float(bookrate)
name = jsonresults['volumeInfo']['authors'][0]
GR = GoodReads(name)
author = GR.find_author_id()
if author:
AuthorID = author['authorid']
controlValueDict = {"BookID": bookid}
newValueDict = {
"AuthorName": authorname,
"AuthorID": AuthorID,
"AuthorLink": "",
"BookName": bookname,
"BookSub": booksub,
"BookDesc": bookdesc,
#.........这里部分代码省略.........
示例8: addBookToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [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)
示例9: LibraryScan
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
#.........这里部分代码省略.........
# we need to add it to language cache if not already
# there, is_valid_isbn has checked length is 10 or 13
if len(isbn) == 10:
isbnhead = isbn[0:3]
else:
isbnhead = isbn[3:6]
match = myDB.action('SELECT lang FROM languages where isbn = "%s"' % (isbnhead)).fetchone()
if not match:
myDB.action('insert into languages values ("%s", "%s")' % (isbnhead, language))
logger.debug("Cached Lang [%s] ISBN [%s]" % (language, isbnhead))
else:
logger.debug("Already cached Lang [%s] ISBN [%s]" % (language, isbnhead))
# get authors name in a consistent format
if "," in author: # "surname, forename"
words = author.split(",")
author = words[1].strip() + " " + words[0].strip() # "forename surname"
if author[1] == " ":
author = author.replace(" ", ".")
author = author.replace("..", ".")
# Check if the author exists, and import the author if not,
# before starting any complicated book-name matching to save repeating the search
#
check_exist_author = myDB.action(
'SELECT * FROM authors where AuthorName="%s"' % author
).fetchone()
if not check_exist_author and lazylibrarian.ADD_AUTHOR:
# no match for supplied author, but we're allowed to
# add new ones
GR = GoodReads(author)
try:
author_gr = GR.find_author_id()
except:
logger.warn("Error finding author id for [%s]" % author)
continue
# only try to add if GR data matches found author data
if author_gr:
authorname = author_gr["authorname"]
# "J.R.R. Tolkien" is the same person as "J. R. R. Tolkien" and "J R R Tolkien"
match_auth = author.replace(".", "_")
match_auth = match_auth.replace(" ", "_")
match_auth = match_auth.replace("__", "_")
match_name = authorname.replace(".", "_")
match_name = match_name.replace(" ", "_")
match_name = match_name.replace("__", "_")
match_name = common.remove_accents(match_name)
match_auth = common.remove_accents(match_auth)
# allow a degree of fuzziness to cater for different accented character handling.
# some author names have accents,
# filename may have the accented or un-accented version of the character
# The currently non-configurable value of fuzziness might need to go in config
# We stored GoodReads unmodified author name in
# author_gr, so store in LL db under that
# fuzz.ratio doesn't lowercase for us
match_fuzz = fuzz.ratio(match_auth.lower(), match_name.lower())
if match_fuzz < 90:
logger.debug("Failed to match author [%s] fuzz [%d]" % (author, match_fuzz))
logger.debug(
"Failed to match author [%s] to authorname [%s]" % (match_auth, match_name)
)
# To save loading hundreds of books by unknown
示例10: LibraryScan
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def LibraryScan(dir=None):
if not dir:
if not lazylibrarian.DOWNLOAD_DIR:
return
else:
dir = lazylibrarian.DOWNLOAD_DIR
if not os.path.isdir(dir):
logger.warn('Cannot find directory: %s. Not scanning' % dir.decode(lazylibrarian.SYS_ENCODING, 'replace'))
return
myDB = database.DBConnection()
new_authors = []
logger.info('Scanning ebook directory: %s' % dir.decode(lazylibrarian.SYS_ENCODING, 'replace'))
book_list = []
new_book_count = 0
file_count = 0
book_exists = False
if (lazylibrarian.FULL_SCAN):
books = myDB.select('select AuthorName, BookName from books where Status=?',[u'Open'])
status = lazylibrarian.NOTFOUND_STATUS
logger.info('Missing books will be marked as %s' % status)
for book in books:
for book_type in getList(lazylibrarian.EBOOK_TYPE):
bookName = book['BookName']
bookAuthor = book['AuthorName']
#Default destination path, should be allowed change per config file.
dest_path = lazylibrarian.EBOOK_DEST_FOLDER.replace('$Author', bookAuthor).replace('$Title', bookName)
#dest_path = authorname+'/'+bookname
global_name = lazylibrarian.EBOOK_DEST_FILE.replace('$Author', bookAuthor).replace('$Title', bookName)
encoded_book_path = os.path.join(dir,dest_path,global_name + "." + book_type).encode(lazylibrarian.SYS_ENCODING)
if os.path.isfile(encoded_book_path):
book_exists = True
if not book_exists:
myDB.action('update books set Status=? where AuthorName=? and BookName=?',[status,bookAuthor,bookName])
logger.info('Book %s updated as not found on disk' % encoded_book_path.decode(lazylibrarian.SYS_ENCODING, 'replace') )
if bookAuthor not in new_authors:
new_authors.append(bookAuthor)
latest_subdirectory = []
for r,d,f in os.walk(dir):
for directory in d[:]:
if directory.startswith("."):
d.remove(directory)
#prevent magazine being scanned
if directory.startswith("_"):
d.remove(directory)
for files in f:
subdirectory = r.replace(dir,'')
latest_subdirectory.append(subdirectory)
logger.info("[%s] Now scanning subdirectory %s" % (dir.decode(lazylibrarian.SYS_ENCODING, 'replace'), subdirectory.decode(lazylibrarian.SYS_ENCODING, 'replace')))
matchString = ''
for char in lazylibrarian.EBOOK_DEST_FILE:
matchString = matchString + '\\' + char
#massage the EBOOK_DEST_FILE config parameter into something we can use with regular expression matching
booktypes = ''
count=-1;
booktype_list = getList(lazylibrarian.EBOOK_TYPE)
for book_type in booktype_list:
count+=1
if count == 0:
booktypes = book_type
else:
booktypes = booktypes + '|'+book_type
matchString = matchString.replace("\\$\\A\\u\\t\\h\\o\\r", "(?P<author>.*?)").replace("\\$\\T\\i\\t\\l\\e","(?P<book>.*?)")+'\.['+booktypes+']'
#pattern = re.compile(r'(?P<author>.*?)\s\-\s(?P<book>.*?)\.(?P<format>.*?)', re.VERBOSE)
pattern = re.compile(matchString, re.VERBOSE)
match = pattern.match(files)
if match:
author = match.group("author")
book = match.group("book")
#check if book is in database, and not marked as in library
check_exist_book = myDB.action("SELECT * FROM books where AuthorName=? and BookName=? and Status!=?",[author,book,'Open']).fetchone()
if not check_exist_book:
check_exist_author = myDB.action("SELECT * FROM authors where AuthorName=?",[author]).fetchone()
if not check_exist_author and lazylibrarian.ADD_AUTHOR:
GR = GoodReads(author)
try:
author_gr = GR.find_author_id()
except:
continue
#only try to add if GR data matches found author data
if author_gr:
authorid = author_gr['authorid']
authorlink = author_gr['authorlink']
pageIdx = authorlink.rfind('/')
authorlink = authorlink[pageIdx+1:]
match_auth = authorid+"."+author.replace('. ','_')
logger.debug(match_auth)
logger.debug(authorlink)
if match_auth == authorlink:
logger.info("Adding %s" % author)
try:
importer.addAuthorToDB(author)
except:
continue
#.........这里部分代码省略.........
示例11: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
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"
# noinspection PyBroadException
try:
myDB = database.DBConnection()
match = False
author = None
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"}
if new_author:
newValueDict["AuthorName"] = "Loading"
newValueDict["AuthorImg"] = "images/nophoto.png"
myDB.upsert("authors", newValueDict, controlValueDict)
GR = GoodReads(authorid)
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["AuthorImg"] = author['authorimg']
newValueDict["AuthorBorn"] = author['authorborn']
newValueDict["AuthorDeath"] = author['authordeath']
if not dbauthor:
newValueDict["AuthorName"] = author['authorname']
elif dbauthor['authorname'] != author['authorname']:
authorname = dbauthor['authorname']
logger.warn("Authorname mismatch for %s [%s][%s]" %
(authorid, dbauthor['authorname'], author['authorname']))
myDB.upsert("authors", newValueDict, controlValueDict)
match = True
else:
logger.warn("Nothing found for %s" % authorid)
if not dbauthor:
myDB.action('DELETE from authors WHERE AuthorID=?', (authorid,))
if authorname and author and not match:
authorname = ' '.join(authorname.split()) # ensure no extra whitespace
GR = GoodReads(authorname)
author = GR.find_author_id(refresh=refresh)
dbauthor = myDB.match("SELECT * from authors WHERE AuthorName=?", (authorname,))
if author and not dbauthor: # may have different name for same authorid (spelling?)
dbauthor = myDB.match("SELECT * from authors WHERE AuthorID=?", (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"
}
#.........这里部分代码省略.........
示例12: find_book
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def find_book(self, bookid=None, bookstatus="None"):
myDB = database.DBConnection()
if not lazylibrarian.CONFIG['GB_API']:
logger.warn('No GoogleBooks API key, check config')
URL = 'https://www.googleapis.com/books/v1/volumes/' + \
str(bookid) + "?key=" + lazylibrarian.CONFIG['GB_API']
jsonresults, in_cache = gb_json_request(URL)
if jsonresults is None:
logger.debug('No results found for %s' % bookid)
return
if not bookstatus:
bookstatus = lazylibrarian.CONFIG['NEWBOOK_STATUS']
book = bookdict(jsonresults)
dic = {':': '.', '"': '', '\'': ''}
bookname = replace_all(book['name'], dic)
bookname = unaccented(bookname)
bookname = bookname.strip() # strip whitespace
if not book['author']:
logger.debug('Book %s does not contain author field, skipping' % bookname)
return
# warn if language is in ignore list, but user said they wanted this book
valid_langs = getList(lazylibrarian.CONFIG['IMP_PREFLANG'])
if book['lang'] not in valid_langs and 'All' not in valid_langs:
logger.debug('Book %s googlebooks language does not match preference, %s' % (bookname, book['lang']))
if lazylibrarian.CONFIG['NO_PUBDATE']:
if not book['date'] or book['date'] == '0000':
logger.warn('Book %s Publication date does not match preference, %s' % (bookname, book['date']))
if lazylibrarian.CONFIG['NO_FUTURE']:
if book['date'] > today()[:4]:
logger.warn('Book %s Future publication date does not match preference, %s' % (bookname, book['date']))
authorname = book['author']
GR = GoodReads(authorname)
author = GR.find_author_id()
if author:
AuthorID = author['authorid']
match = myDB.match('SELECT AuthorID from authors WHERE AuthorID=?', (AuthorID,))
if not match:
match = myDB.match('SELECT AuthorID from authors WHERE AuthorName=?', (author['authorname'],))
if match:
logger.debug('%s: Changing authorid from %s to %s' %
(author['authorname'], AuthorID, match['AuthorID']))
AuthorID = match['AuthorID'] # we have a different authorid for that authorname
else: # no author but request to add book, add author with newauthor status
# User hit "add book" button from a search or a wishlist import
newauthor_status = 'Active'
if lazylibrarian.CONFIG['NEWAUTHOR_STATUS'] in ['Skipped', 'Ignored']:
newauthor_status = 'Paused'
controlValueDict = {"AuthorID": AuthorID}
newValueDict = {
"AuthorName": author['authorname'],
"AuthorImg": author['authorimg'],
"AuthorLink": author['authorlink'],
"AuthorBorn": author['authorborn'],
"AuthorDeath": author['authordeath'],
"DateAdded": today(),
"Status": newauthor_status
}
authorname = author['authorname']
myDB.upsert("authors", newValueDict, controlValueDict)
if lazylibrarian.CONFIG['NEWAUTHOR_BOOKS']:
self.get_author_books(AuthorID, entrystatus=lazylibrarian.CONFIG['NEWAUTHOR_STATUS'])
else:
logger.warn("No AuthorID for %s, unable to add book %s" % (book['author'], bookname))
return
controlValueDict = {"BookID": bookid}
newValueDict = {
"AuthorID": AuthorID,
"BookName": bookname,
"BookSub": book['sub'],
"BookDesc": book['desc'],
"BookIsbn": book['isbn'],
"BookPub": book['pub'],
"BookGenre": book['genre'],
"BookImg": book['img'],
"BookLink": book['link'],
"BookRate": float(book['rate']),
"BookPages": book['pages'],
"BookDate": book['date'],
"BookLang": book['lang'],
"Status": bookstatus,
"AudioStatus": lazylibrarian.CONFIG['NEWAUDIO_STATUS'],
"BookAdded": today()
}
myDB.upsert("books", newValueDict, controlValueDict)
logger.info("%s by %s added to the books database" % (bookname, authorname))
if 'nocover' in book['img'] or 'nophoto' in book['img']:
# try to get a cover from another source
workcover, source = getBookCover(bookid)
if workcover:
#.........这里部分代码省略.........
示例13: find_book
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def find_book(self, bookid=None, queue=None):
threading.currentThread().name = "GB-ADD-BOOK"
myDB = database.DBConnection()
URL = "https://www.googleapis.com/books/v1/volumes/" + str(bookid) + "?key=" + lazylibrarian.GB_API
jsonresults = json.JSONDecoder().decode(urllib2.urlopen(URL, timeout=30).read())
bookname = jsonresults["volumeInfo"]["title"]
try:
authorname = jsonresults["volumeInfo"]["authors"][0]
except KeyError:
logger.debug("Book %s does not contain author field" % bookname)
try:
# skip if language is in ignore list
booklang = jsonresults["volumeInfo"]["language"]
valid_langs = [valid_lang.strip() for valid_lang in lazylibrarian.IMP_PREFLANG.split(",")]
if booklang not in valid_langs:
logger.debug("Book %s language does not match preference" % bookname)
except KeyError:
logger.debug("Book does not have language field")
try:
bookpub = jsonresults["volumeInfo"]["publisher"]
except KeyError:
bookpub = None
try:
booksub = jsonresults["volumeInfo"]["subtitle"]
except KeyError:
booksub = None
try:
bookdate = jsonresults["volumeInfo"]["publishedDate"]
except KeyError:
bookdate = "0000-00-00"
try:
bookimg = jsonresults["volumeInfo"]["imageLinks"]["thumbnail"]
except KeyError:
bookimg = "images/nocover.png"
try:
bookrate = jsonresults["volumeInfo"]["averageRating"]
except KeyError:
bookrate = 0
try:
bookpages = jsonresults["volumeInfo"]["pageCount"]
except KeyError:
bookpages = 0
try:
bookgenre = jsonresults["volumeInfo"]["categories"][0]
except KeyError:
bookgenre = None
try:
bookdesc = jsonresults["volumeInfo"]["description"]
except KeyError:
bookdesc = None
try:
if jsonresults["volumeInfo"]["industryIdentifiers"][0]["type"] == "ISBN_10":
bookisbn = jsonresults["volumeInfo"]["industryIdentifiers"][0]["identifier"]
else:
bookisbn = None
except KeyError:
bookisbn = None
booklink = jsonresults["volumeInfo"]["canonicalVolumeLink"]
bookrate = float(bookrate)
name = jsonresults["volumeInfo"]["authors"][0]
GR = GoodReads(name)
author = GR.find_author_id()
if author:
AuthorID = author["authorid"]
controlValueDict = {"BookID": bookid}
newValueDict = {
"AuthorName": authorname,
"AuthorID": AuthorID,
"AuthorLink": "",
"BookName": bookname,
"BookSub": booksub,
"BookDesc": bookdesc,
"BookIsbn": bookisbn,
"BookPub": bookpub,
"BookGenre": bookgenre,
"BookImg": bookimg,
"BookLink": booklink,
"BookRate": bookrate,
"BookPages": bookpages,
"BookDate": bookdate,
"BookLang": booklang,
"Status": "Wanted",
"BookAdded": formatter.today(),
}
#.........这里部分代码省略.........
示例14: addAuthorToDB
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def addAuthorToDB(authorname=None):
threading.currentThread().name = "DBIMPORT"
type = 'author'
myDB = database.DBConnection()
GR = GoodReads(authorname, type)
GB = GoogleBooks(authorname, type)
query = "SELECT * from authors WHERE AuthorName='%s'" % authorname
dbauthor = myDB.action(query).fetchone()
controlValueDict = {"AuthorName": authorname}
if dbauthor is None:
newValueDict = {
"AuthorID": "0: %s" % (authorname),
"Status": "Loading"
}
else:
newValueDict = {"Status": "Loading"}
myDB.upsert("authors", newValueDict, controlValueDict)
author = GR.find_author_id()
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": formatter.today(),
"Status": "Loading"
}
myDB.upsert("authors", newValueDict, controlValueDict)
else:
logger.error("Nothing found")
# process books
bookscount = 0
books = GB.find_results()
for book in books:
# this is for rare cases where google returns multiple authors who share nameparts
if book['authorname'] == authorname:
controlValueDict = {"BookID": book['bookid']}
newValueDict = {
"AuthorName": book['authorname'],
"AuthorID": authorid,
"AuthorLink": authorimg,
"BookName": book['bookname'],
"BookSub": book['booksub'],
"BookDesc": book['bookdesc'],
"BookIsbn": book['bookisbn'],
"BookPub": book['bookpub'],
"BookGenre": book['bookgenre'],
"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)
bookscount = bookscount+1
lastbook = myDB.action("SELECT BookName, BookLink, BookDate from books WHERE AuthorName='%s' order by BookDate DESC" % authorname).fetchone()
controlValueDict = {"AuthorName": authorname}
newValueDict = {
"Status": "Active",
"TotalBooks": bookscount,
"LastBook": lastbook['BookName'],
"LastLink": lastbook['BookLink'],
"LastDate": lastbook['BookDate']
}
myDB.upsert("authors", newValueDict, controlValueDict)
logger.info("Processing complete: Added %s books to the database" % bookscount)
示例15: find_book
# 需要导入模块: from lazylibrarian.gr import GoodReads [as 别名]
# 或者: from lazylibrarian.gr.GoodReads import find_author_id [as 别名]
def find_book(self, bookid=None, queue=None):
threading.currentThread().name = "GB-ADD-BOOK"
myDB = database.DBConnection()
if not lazylibrarian.GB_API:
logger.warn("No GoogleBooks API key, check config")
URL = "https://www.googleapis.com/books/v1/volumes/" + str(bookid) + "?key=" + lazylibrarian.GB_API
jsonresults, in_cache = self.get_request(URL)
# Darkie67:
# replacing German Umlauts and filtering out ":"
#
# booknamealt = jsonresults['volumeInfo']['title']
# booknametmp1=booknamealt.replace(u'\xf6',u'oe')
# booknametmp2=booknametmp1.replace(u'\xe4',u'ae')
# booknametmp3=booknametmp2.replace(u'\xdf',u'ss')
# booknametmp4=booknametmp3.replace(u'\xc4',u'Ae')
# booknametmp5=booknametmp4.replace(u'\xdc',u'Ue')
# booknametmp6=booknametmp5.replace(u'\xd6',u'Oe')
# booknametmp7=booknametmp6.replace(':','')
# bookname=booknametmp7.replace(u'\xfc',u'ue')
bookname = jsonresults["volumeInfo"]["title"]
bookname = bookname.replace(":", "").replace('"', "").replace("'", "")
bookname = unidecode(u"%s" % bookname)
bookname = bookname.strip() # strip whitespace
# Darkie67 end
try:
authorname = jsonresults["volumeInfo"]["authors"][0]
except KeyError:
logger.debug("Book %s does not contain author field, skipping" % bookname)
return
try:
# warn if language is in ignore list, but user said they wanted this book
booklang = jsonresults["volumeInfo"]["language"]
valid_langs = [valid_lang.strip() for valid_lang in lazylibrarian.IMP_PREFLANG.split(",")]
if booklang not in valid_langs:
logger.debug("Book %s language does not match preference" % bookname)
except KeyError:
logger.debug("Book does not have language field")
booklang = "Unknown"
try:
bookpub = jsonresults["volumeInfo"]["publisher"]
except KeyError:
bookpub = None
try:
booksub = jsonresults["volumeInfo"]["subtitle"]
except KeyError:
booksub = None
try:
bookdate = jsonresults["volumeInfo"]["publishedDate"]
except KeyError:
bookdate = "0000-00-00"
try:
bookimg = jsonresults["volumeInfo"]["imageLinks"]["thumbnail"]
except KeyError:
bookimg = "images/nocover.png"
try:
bookrate = jsonresults["volumeInfo"]["averageRating"]
except KeyError:
bookrate = 0
try:
bookpages = jsonresults["volumeInfo"]["pageCount"]
except KeyError:
bookpages = 0
try:
bookgenre = jsonresults["volumeInfo"]["categories"][0]
except KeyError:
bookgenre = None
try:
bookdesc = jsonresults["volumeInfo"]["description"]
except KeyError:
bookdesc = None
try:
if jsonresults["volumeInfo"]["industryIdentifiers"][0]["type"] == "ISBN_10":
bookisbn = jsonresults["volumeInfo"]["industryIdentifiers"][0]["identifier"]
else:
bookisbn = None
except KeyError:
bookisbn = None
booklink = jsonresults["volumeInfo"]["canonicalVolumeLink"]
bookrate = float(bookrate)
name = jsonresults["volumeInfo"]["authors"][0]
GR = GoodReads(name)
author = GR.find_author_id()
if author:
AuthorID = author["authorid"]
controlValueDict = {"BookID": bookid}
newValueDict = {
"AuthorName": authorname,
#.........这里部分代码省略.........