def pybtex_to_pieberry(key, ent): '''Transform pybtex Entry class to a PieObject''' obj = PieObject() modfields = {} for bkey, val in ent.fields.items(): if bibtexmap.has_key(bkey): modfields[bibtexmap[bkey]] = ublc(val) obj.add_aspect_bibdata(**modfields) obj.BibData_Key = key if not ent.fields.has_key('title'): if ent.fields.has_key('booktitle'): obj.title = ublc(ent.items['booktitle']) else: raise ValueError, 'No title in this entry' for persons in ent.persons.itervalues(): for person in persons: person.text = unicode(person) formatter = Formatter() formatted_names = formatter.format_people(ent) # formatted_names = formatter.format_author_or_editor(ent) rendered_names = formatted_names.render(plaintext.Backend()).rstrip('.') corpnamehere = re_corpname.match(rendered_names) if not ent.fields.has_key('year'): raise Exception, "No valid date for this item" if not ent.fields.has_key('month'): ent.fields['month'] = 'January' datestr = '01 %s %s' % (ent.fields['month'], ent.fields['year']) obj.BibData_DatePublished = datetime.datetime.strptime(datestr, '%d %B %Y') if corpnamehere: rendered_names = '%s%s' % (corpnamehere.group(1), corpnamehere.group(2)) obj.corpauthor = rendered_names else: obj.author = rendered_names obj.BibData_Type = ent.type return obj
def pieberry_from_google(gdict, url): '''Take a google books dict and produce a PieObject''' bd = { 'title': unicode(gdict['title'], 'utf8'), } if gdict.has_key('authors') and gdict['authors']: bd['author'] = fmt_authors(gdict['authors']) try: bd['BibData_DatePublished'] = datetime.datetime.strptime( gdict['date'], '%Y-%m-%d') except: try: bd['BibData_DatePublished'] = datetime.datetime.strptime( gdict['date'], '%Y') except: bd['BibData_DatePublished'] = datetime.datetime.today() if gdict.has_key('description') and gdict['description']: bd['BibData_Abstract'] = unicode(gdict['description'], 'utf8') if gdict.has_key('publishers') and gdict['publishers']: bd['BibData_Publisher'] = u' - '.join( [unicode(p, 'utf8') for p in gdict['publishers']]) googlekey = '' for i, k in gdict['identifiers']: if i == 'ISBN': bd['PhysData_ISBN'] = k elif i == 'google_id': googlekey = k bd['BibData_Type'] = suggest_type(gdict, bd) bd['WebData_Url'] = url obj = PieObject() obj.GoogleData = {'google_id': googlekey} if gdict.has_key('subjects'): obj.GoogleData['subjects'] = gdict['subjects'] if gdict.has_key('thumbnail'): obj.GoogleData['thumbnail'] = gdict['thumbnail'] if gdict.has_key('summary'): obj.GoogleData['summary'] = gdict['summary'] obj.add_aspect_bibdata(**bd) return obj
def pieberry_from_google(gdict, url): '''Take a google books dict and produce a PieObject''' bd = { 'title': unicode(gdict['title'], 'utf8'), } if gdict.has_key('authors') and gdict['authors']: bd['author'] = fmt_authors(gdict['authors']) try: bd['BibData_DatePublished'] = datetime.datetime.strptime( gdict['date'], '%Y-%m-%d') except: try: bd['BibData_DatePublished'] = datetime.datetime.strptime( gdict['date'], '%Y') except: bd['BibData_DatePublished'] = datetime.datetime.today() if gdict.has_key('description') and gdict['description']: bd['BibData_Abstract'] = unicode(gdict['description'], 'utf8') if gdict.has_key('publishers') and gdict['publishers']: bd['BibData_Publisher'] = u' - '.join([unicode(p, 'utf8') for p in gdict['publishers']]) googlekey = '' for i, k in gdict['identifiers']: if i == 'ISBN': bd['PhysData_ISBN'] = k elif i == 'google_id': googlekey = k bd['BibData_Type'] = suggest_type(gdict, bd) bd['WebData_Url'] = url obj = PieObject() obj.GoogleData = {'google_id': googlekey} if gdict.has_key('subjects'): obj.GoogleData['subjects'] = gdict['subjects'] if gdict.has_key('thumbnail'): obj.GoogleData['thumbnail'] = gdict['thumbnail'] if gdict.has_key('summary'): obj.GoogleData['summary'] = gdict['summary'] obj.add_aspect_bibdata(**bd) return obj
def pybtex_to_pieberry(key, ent): '''Transform pybtex Entry class to a PieObject''' obj = PieObject() modfields = {} for bkey, val in ent.fields.items(): if bibtexmap.has_key(bkey): modfields[bibtexmap[bkey]] = ublc(val) obj.add_aspect_bibdata(**modfields) obj.BibData_Key = key if not ent.fields.has_key('title'): if ent.fields.has_key('booktitle'): obj.title = ublc(ent.items['booktitle']) else: raise ValueError, 'No title in this entry' for persons in ent.persons.itervalues(): for person in persons: person.text = unicode(person) formatter = Formatter() formatted_names = formatter.format_people(ent) # formatted_names = formatter.format_author_or_editor(ent) rendered_names = formatted_names.render(plaintext.Backend()).rstrip('.') corpnamehere = re_corpname.match(rendered_names) if not ent.fields.has_key('year'): raise Exception, "No valid date for this item" if not ent.fields.has_key('month'): ent.fields['month'] = 'January' datestr = '01 %s %s' % (ent.fields['month'], ent.fields['year']) obj.BibData_DatePublished = datetime.datetime.strptime(datestr, '%d %B %Y') if corpnamehere: rendered_names = '%s%s' % (corpnamehere.group(1), corpnamehere.group(2)) obj.corpauthor = rendered_names else: obj.author = rendered_names obj.BibData_Type = ent.type return obj