fikset litt på gdata-modulen

This commit is contained in:
Øyvind Almelid 2010-09-24 15:28:09 +00:00
parent 9d3d77cbf6
commit 46398a5b49
3 changed files with 19 additions and 6 deletions

View File

@ -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:]:

View File

@ -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:

View File

@ -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)