Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

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' _tag = 'entry'
_namespace = atom.ATOM_NAMESPACE _namespace = atom.ATOM_NAMESPACE
_children = gdata.GDataEntry._children.copy() _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]) _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 Review, Rating): # Review, Rating maybe only in anno/lib entrys
_children['{%s}%s' % (i._namespace, i._tag)] = (i._tag, i) _children['{%s}%s' % (i._namespace, i._tag)] = (i._tag, i)
# there is an atom title as well, should we clobber that? # there is an atom title as well, should we clobber that?
@ -332,7 +332,7 @@ class Book(_AtomFromString, gdata.GDataEntry):
if self.description: if self.description:
d['description'] = self.description.text d['description'] = self.description.text
if self.format: if self.format:
d['format'] = self.format.text d['format'] = [x.text for x in self.format]
if self.identifier: if self.identifier:
d['identifiers'] = [('google_id', self.identifier[0].text)] d['identifiers'] = [('google_id', self.identifier[0].text)]
for x in self.identifier[1:]: for x in self.identifier[1:]:

View File

@ -2,6 +2,7 @@
from web.library.models import * from web.library.models import *
from gdata.books.service import BookService from gdata.books.service import BookService
import re
exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q'] exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
@ -22,8 +23,8 @@ def get_book_loop():
def build_book(entry, input=False): def build_book(entry, input=False):
dic = entry.to_dict() dic = entry.to_dict()
# print dic print dic
print entry # print entry
b = Book(title=entry.dc_title[0].text) b = Book(title=entry.dc_title[0].text)
if len(entry.dc_title) > 0: if len(entry.dc_title) > 0:
b.subtitle = ''.join(map(lambda x: x.text, entry.dc_title[1:])) 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]) b.published_year = int(dic['date'][:4])
if 'publishers' in dic: if 'publishers' in dic:
b.publisher = ','.join(dic['publishers']) b.publisher = ','.join(dic['publishers'])
print entry.format b.num_pages = find_page_number(dic)
b.full_print() 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): def find_isbn(identifiers):
for pair in identifiers: for pair in identifiers:
if pair[0] =='ISBN' and len(pair[1])==13: if pair[0] =='ISBN' and len(pair[1])==13:

View File

@ -43,6 +43,9 @@ class Book(models.Model):
except Category.DoesNotExist: except Category.DoesNotExist:
print '%-15s: %50s' % (field[1], 'Does not exist') print '%-15s: %50s' % (field[1], 'Does not exist')
class Meta:
unique_together=(("isbn","id"),)
class AlternativeTitle(models.Model): class AlternativeTitle(models.Model):
book = models.ForeignKey(Book) book = models.ForeignKey(Book)
alt_title = models.CharField(max_length=511) alt_title = models.CharField(max_length=511)