From f49688fdb955df45e9b43b8513ed7d801ea13f99 Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 6 Sep 2020 19:31:03 +0200 Subject: [PATCH] Fix #1461 (parse Amazon_* identifiers) --- cps/db.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/cps/db.py b/cps/db.py index 2cf1d98b..2dfd92c1 100644 --- a/cps/db.py +++ b/cps/db.py @@ -103,41 +103,49 @@ class Identifiers(Base): # return {self.type: self.val} def formatType(self): - if self.type == "amazon": + format_type = self.type.lower() + if format_type == 'amazon': return u"Amazon" - elif self.type == "isbn": + elif format_type.startswith("amazon_"): + return u"Amazon.{0}".format(format_type[7:]) + elif format_type == "isbn": return u"ISBN" - elif self.type == "doi": + elif format_type == "doi": return u"DOI" - elif self.type == "goodreads": + elif format_type == "douban": + return u"Douban" + elif format_type == "goodreads": return u"Goodreads" - elif self.type == "google": + elif format_type == "google": return u"Google Books" - elif self.type == "kobo": + elif format_type == "kobo": return u"Kobo" - if self.type == "lubimyczytac": + if format_type == "lubimyczytac": return u"Lubimyczytac" else: return self.type def __repr__(self): - if self.type == "amazon" or self.type == "asin": + format_type = self.type.lower() + if format_type == "amazon" or format_type == "asin": return u"https://amzn.com/{0}".format(self.val) - elif self.type == "isbn": + elif format_type.startswith('amazon_'): + return u"https://amazon.{0}/{1}".format(format_type[7:], self.val) + elif format_type == "isbn": return u"https://www.worldcat.org/isbn/{0}".format(self.val) - elif self.type == "doi": + elif format_type == "doi": return u"https://dx.doi.org/{0}".format(self.val) - elif self.type == "goodreads": + elif format_type == "goodreads": return u"https://www.goodreads.com/book/show/{0}".format(self.val) - elif self.type == "douban": + elif format_type == "douban": return u"https://book.douban.com/subject/{0}".format(self.val) - elif self.type == "google": + elif format_type == "google": return u"https://books.google.com/books?id={0}".format(self.val) - elif self.type == "kobo": + elif format_type == "kobo": return u"https://www.kobo.com/ebook/{0}".format(self.val) - elif self.type == "lubimyczytac": + elif format_type == "lubimyczytac": return u" https://lubimyczytac.pl/ksiazka/{0}".format(self.val) - elif self.type == "url": + elif format_type == "url": return u"{0}".format(self.val) else: return u""