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

Ugly encoding hacks.

This commit is contained in:
Øystein Ingmar Skartsæterhagen 2011-10-08 19:41:57 +00:00
parent 3c911d3131
commit 9e84d0cfcd
1 changed files with 8 additions and 6 deletions

View File

@ -15,6 +15,8 @@ exit_commands = ['exit', 'abort', 'quit', 'bye', 'eat flaming death', 'q']
comments = ""
encoding = 'utf8'
# midlertidig
connection = pgdb.connect(database='oysteini_pbb2',
user='oysteini_pbb',
@ -114,18 +116,18 @@ def build_book(entry, authors, indata=False):
comment("No ISBN found.")
return False
book['title'] = unicode(entry.dc_title[0].text)
book['title'] = unicode(entry.dc_title[0].text, encoding)
set_value(book, dic, 'category')
if len(entry.dc_title) > 0:
book['subtitle'] = unicode(''.join(map(lambda x: x.text, entry.dc_title[1:])))
book['subtitle'] = unicode(''.join(map(lambda x: x.text, entry.dc_title[1:])), encoding)
book['persons'] = {}
book['persons']['author'] = [author['id'] for author in authors]
if 'publishers' in dic:
book['publisher'] = unicode(','.join(dic['publishers']))
book['publisher'] = unicode(','.join(dic['publishers']), encoding)
if 'date' in dic:
book['published_year'] = int(dic['date'][:4])
@ -136,10 +138,10 @@ def build_book(entry, authors, indata=False):
set_value(book, dic, 'series')
book['description'] = unicode(find_description(dic))
book['description'] = unicode(find_description(dic), encoding)
book['references'] = {}
book['references']['google-books'] = [unicode(dic['preview'])]
book['references']['google-books'] = [unicode(dic['preview'], encoding)]
return book
@ -149,7 +151,7 @@ def comment(comm):
def set_value(book, dic, key):
if key in dic:
book[key] = unicode(dic[key])
book[key] = unicode(dic[key], encoding)
else:
book[key] = None