#2 er foreløpig ferdig. Denne versjonen har litt penere kode, og ser ut til å fungere fint. Action-lista blir fremdeles printa til standard ut.
This commit is contained in:
parent
bc1ba7e631
commit
aff4e4c2a2
|
@ -4,9 +4,6 @@ import os
|
|||
os.environ['DJANGO_SETTINGS_MODULE']='web.settings'
|
||||
from web.library.models import *
|
||||
from gdata.books.service import BookService
|
||||
#from dibbler_snippet import ConfirmMenu
|
||||
#from xml.dom import minidom
|
||||
#from xml.sax.saxutils import unescape
|
||||
import xml.parsers.expat
|
||||
import readline
|
||||
import re
|
||||
|
@ -35,13 +32,13 @@ def get_book_loop():
|
|||
print "Found multiple books: "
|
||||
for i in range(len(feed.entry)): #entry in feed.entry:
|
||||
print "%d: %s" % (i,
|
||||
# build_authors(feed.entry[i].to_dict())[0],
|
||||
feed.entry[i].dc_title[0].text)
|
||||
bookno = (int)(raw_input("Which book do you want? [0-%d] " % (len(feed.entry) - 1)))
|
||||
action_list.append(build_book(feed.entry[bookno], indata))
|
||||
else:
|
||||
print "No items found"
|
||||
|
||||
print
|
||||
print write_actionlist(action_list)
|
||||
|
||||
def found_item(entry, indata):
|
||||
|
@ -94,7 +91,6 @@ def build_book(entry, indata=False):
|
|||
book['references']['google-books'] = [unicode(dic['preview'])]
|
||||
|
||||
global comments
|
||||
print comments
|
||||
book['comment'] = comments
|
||||
comments = ''
|
||||
|
||||
|
@ -143,7 +139,6 @@ def build_authors(dictionary):
|
|||
return []
|
||||
|
||||
def get_or_create_author(author_name):
|
||||
# print "Processing author: ", author_name
|
||||
global action_list
|
||||
author = {}
|
||||
author['action'] = 'new-person'
|
||||
|
@ -153,16 +148,13 @@ def get_or_create_author(author_name):
|
|||
author['first_name'] = first
|
||||
author['last_name'] = last
|
||||
candidates = Person.objects.filter(first_name__contains=names[0],last_name=last)
|
||||
# comment("Authors found: %s" % (', '.join(str(v) for v in )))
|
||||
selected = select_from_list(candidates, attributes=['first_name','last_name'], item_name='author')
|
||||
if selected:
|
||||
return selected
|
||||
else:
|
||||
# print "No author found, creating author"
|
||||
comment("No author found, creating author.")
|
||||
newid = ''.join([i[0] for i in names]).lower()
|
||||
author['id'] = newid
|
||||
# print newid
|
||||
while True:
|
||||
existing = Person.objects.filter(id=newid)
|
||||
if len(existing)==0:
|
||||
|
@ -171,27 +163,16 @@ def get_or_create_author(author_name):
|
|||
comment("Another author found with same initials, please fix id.")
|
||||
newid = newid+"%f" % random.random()
|
||||
author['id'] = newid
|
||||
# newid = raw_input("Another author found with same intials, please suggest an id> ")
|
||||
|
||||
|
||||
#Cargo-cult coded function to unescape special XML characters
|
||||
|
||||
def select_from_list(list, attributes=False, item_name=""):
|
||||
if len(list) == 0:
|
||||
# print "No candidate %sfound" %(item_name+' ')
|
||||
return None
|
||||
elif len(list) == 1:
|
||||
# if attributes:
|
||||
# answer = raw_input(str("Found one %s: %s. Use this? [y]/n> " %(item_name,' '.join([eval("list[0]."+attribute) for attribute in attributes]))))
|
||||
# else:
|
||||
# answer = raw_input(str("Found one %s: %s. Use this? [y]/n> " %(item_name,list[0])))
|
||||
# if answer in ['yes', 'y', '']:
|
||||
# return list[0]
|
||||
# else:
|
||||
# return None
|
||||
return list[0]
|
||||
else:
|
||||
# print "several candidates found"
|
||||
return None
|
||||
|
||||
def unescape(s):
|
||||
|
|
Reference in New Issue