elif book['Short Book Description']: edition['description'] = book['Short Book Description'] #print edition author['editions'].append(edition) #sys.exit(0) print len(authors) authors_done = set([u'Zoe Winters', u'Derek Ciccone', u'Shayne Parkinson', u'Joanna Penn']) if False: for k in [u'Zoe Winters', u'Derek Ciccone', u'Shayne Parkinson', u'Joanna Penn']: v = authors[k] akey = ol.new({ 'type': '/type/author', 'name': k, 'bio': v['bio'], }) print print akey, k for e in v['editions']: wkey = ol.new({ 'type': '/type/work', 'title': e['title'], 'authors': [{'author': {'key': akey}}], 'description': e['description'], 'subjects': ['Lending library'], }) print wkey, e['title'] edition = { 'type': '/type/edition',
work_title[k] = w['title'] if not fix_redirects: print 'no redirects left' break print 'save redirects' ol.save_many(fix_redirects, "merge works") all_existing = set() work_keys = [] for w in works: existing = set() for e in w['editions']: existing.update(edition_to_work[e]) if not existing: # editions have no existing work if do_updates: wkey = ol.new({'title': w['title'], 'type': '/type/work'}) print 'new work:', wkey, `w['title']` #print 'new work:', `w['title']` update = [] for ekey in w['editions']: e = ol.get(ekey) if do_updates: e['works'] = [Reference(wkey)] update.append(e) if do_updates: ol.save_many(update, "add editions to new work") work_keys.append(wkey) elif len(existing) == 1: key = list(existing)[0] work_keys.append(key) if work_title[key] == w['title']:
if not w.get('description'): w['description'] = edition['description'] if 'Lending library' not in w.get('subjects', []): w.setdefault('subjects', []).append('Lending library') ol.save(wkey, w, 'Add lending edition from Smashwords') continue q = {'type': '/type/edition', 'ocaid': edition['ia']} existing = list(ol.query(q)) if existing: print existing print 'skip existing:', str(existing[0]), edition['ia'] continue e = { 'type': '/type/edition', 'title': edition['title'], 'authors': [{'key': akey}], 'works': [{'key': wkey}], 'ocaid': edition['ia'], 'publishers': ['Smashwords'], 'publish_date': edition['publish_date'], } if 'isbn' in edition: e['isbn'] = edition['isbn'] ekey = ol.new(e, 'Add lending edition from Smashwords') print ekey, e['ocaid'], e['title'] done.append(e['ocaid']) print done
ol.save(wkey, w, 'Add lending edition from Smashwords') continue q = {'type': '/type/edition', 'ocaid': edition['ia']} existing = list(ol.query(q)) if existing: print existing print 'skip existing:', str(existing[0]), edition['ia'] continue e = { 'type': '/type/edition', 'title': edition['title'], 'authors': [{ 'key': akey }], 'works': [{ 'key': wkey }], 'ocaid': edition['ia'], 'publishers': ['Smashwords'], 'publish_date': edition['publish_date'], } if 'isbn' in edition: e['isbn'] = edition['isbn'] ekey = ol.new(e, 'Add lending edition from Smashwords') print ekey, e['ocaid'], e['title'] done.append(e['ocaid']) print done