From 46398a5b49a2c2d1d613d0c1bd1f69e25436c480 Mon Sep 17 00:00:00 2001 From: almelid Date: Fri, 24 Sep 2010 15:28:09 +0000 Subject: [PATCH] =?UTF-8?q?fikset=20litt=20p=C3=A5=20gdata-modulen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/gdata/books/__init__.py | 6 +++--- python/google_interface.py | 16 +++++++++++++--- python/web/library/models.py | 3 +++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/python/gdata/books/__init__.py b/python/gdata/books/__init__.py index 1a961ab..301361f 100644 --- a/python/gdata/books/__init__.py +++ b/python/gdata/books/__init__.py @@ -289,9 +289,9 @@ class Book(_AtomFromString, gdata.GDataEntry): _tag = 'entry' _namespace = atom.ATOM_NAMESPACE _children = gdata.GDataEntry._children.copy() - for i in (Creator, Identifier, Publisher, Subject,): + for i in (Creator, Identifier, Publisher, Subject, Format): _children['{%s}%s' % (i._namespace, i._tag)] = (i._tag, [i]) - for i in (Date, Description, Format, Viewability, Embeddability, + for i in (Date, Description, Viewability, Embeddability, Review, Rating): # Review, Rating maybe only in anno/lib entrys _children['{%s}%s' % (i._namespace, i._tag)] = (i._tag, i) # there is an atom title as well, should we clobber that? @@ -332,7 +332,7 @@ class Book(_AtomFromString, gdata.GDataEntry): if self.description: d['description'] = self.description.text if self.format: - d['format'] = self.format.text + d['format'] = [x.text for x in self.format] if self.identifier: d['identifiers'] = [('google_id', self.identifier[0].text)] for x in self.identifier[1:]: diff --git a/python/google_interface.py b/python/google_interface.py index 74664fa..56218a6 100644 --- a/python/google_interface.py +++ b/python/google_interface.py @@ -2,6 +2,7 @@ from web.library.models import * from gdata.books.service import BookService +import re exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q'] @@ -22,8 +23,8 @@ def get_book_loop(): def build_book(entry, input=False): dic = entry.to_dict() -# print dic - print entry + print dic +# print entry b = Book(title=entry.dc_title[0].text) if len(entry.dc_title) > 0: b.subtitle = ''.join(map(lambda x: x.text, entry.dc_title[1:])) @@ -42,9 +43,18 @@ def build_book(entry, input=False): b.published_year = int(dic['date'][:4]) if 'publishers' in dic: b.publisher = ','.join(dic['publishers']) - print entry.format + b.num_pages = find_page_number(dic) b.full_print() +def find_page_number(dic): + if 'format' in dic: + for item in dic['format']: + if 'pages' in item: + return int(re.findall(r'[0-9]+',item)[0]) + return None + else: + return None + def find_isbn(identifiers): for pair in identifiers: if pair[0] =='ISBN' and len(pair[1])==13: diff --git a/python/web/library/models.py b/python/web/library/models.py index eb592ed..e6cd4e7 100644 --- a/python/web/library/models.py +++ b/python/web/library/models.py @@ -42,6 +42,9 @@ class Book(models.Model): print '%-15s: %50s' % (field[1],eval('self.'+field[0])) except Category.DoesNotExist: print '%-15s: %50s' % (field[1], 'Does not exist') + + class Meta: + unique_together=(("isbn","id"),) class AlternativeTitle(models.Model): book = models.ForeignKey(Book)