def format_key(self, item, zot_item, bb_citekeys): """ Returns: A user formatted key if present, or a better bibtex key, or zotero hash. """ if self.context['key_format'] > "": title = compat_str(zot_item.title.lower()) title = self.context['key_title_banned_regex'].sub("", title) title = title.partition(" ")[0] date = item.date # Use the allready formatted date author = compat_str(zot_item.format_first_author().replace( " ", "_")) replacements = { u"zotero_key": item.zotero_key, u"title": title.lower(), u"Title": title.capitalize(), u"author": author.lower(), u"Author": author.capitalize(), u"date": date.replace(' ', '-').capitalize() # Date may be 'In-press' etc. } key_format = u'%s' % self.context['key_format'] key = key_format.format(**replacements) key = self.context['key_clean_regex'].sub("", key) return key elif zot_item.id in bb_citekeys: return bb_citekeys[zot_item.id] else: return zot_item.key
def combine(self): pairs = collections.OrderedDict( [ ("Key", self.key), ("Title", self.title), ("Author(s)", self.author), ("Date", self.date), ("Tags", self.tags), ("Collections", ", ".join(self.collections)), ("Publication", self.publication), ("Issue", self.issue), ("Volume", self.volume), ("Pages", self.pages), ("Publisher", self.publisher), ("Language", self.language), ("Abstract", self.abstract), ("Notes", self.notes), ("File(s)", self.file), ("URL", self.url), ("DOI", self.doi), ("ISBN", self.isbn), ] ) self.combined = u"Available citation information:\n" for key, value in pairs.items(): if value: self.combined += " " + key + " : " + compat_str(value) + "\n"
def combine(self): pairs = collections.OrderedDict([('Key', self.key), ('Title', self.title), ('Type', self.type), ('Author(s)', self.author), ('Date', self.date), ('Tags', self.tags), ('Collections', ', '.join(self.collections)), ('Publication', self.publication), ('Issue', self.issue), ('Volume', self.volume), ('Pages', self.pages), ('Publisher', self.publisher), ('Language', self.language), ('Abstract', self.abstract), ('Notes', self.notes), ('File(s)', self.file), ('URL', self.url), ('DOI', self.doi), ('ISBN', self.isbn), ('Zotero key', self.zotero_key)]) self.combined = u"Available citation fields:\n" for key, value in pairs.items(): if value: self.combined += " " + key + " : " + compat_str(value) + "\n"
def get_console_context(context): context.bibtex_file = sys.argv[1] context.zotero_path = sys.argv[1] context.mode = sys.argv[2] context.source_field = sys.argv[3] if context.mode == u'zotero': context.searchkeys = compat_str(sys.argv[4]).split() context.zotero_version = int(sys.argv[5]) return context
def get_console_context(context): context['bibtex_file'] = sys.argv[1] context['zotero_path'] = sys.argv[1] context['mode'] = sys.argv[2] context['source_field'] = sys.argv[3] if context['mode'] == u'zotero': context['searchkeys'] = compat_str(sys.argv[4]).split() context['zotero_version'] = int(sys.argv[5]) return context
def custom_key(self, item, zot_item): title = compat_str(zot_item.title.lower()) title = self.context['key_title_banned_regex'].sub('', title) title = title.partition(' ')[0] date = item.date # Use the allready formatted date author = compat_str(zot_item.format_first_author().replace(" ", "_")) replacements = { u"zotero_key": item.zotero_key, u"title": title.lower(), u"Title": title.capitalize(), u"author": author.lower(), u"Author": author.capitalize(), u"date": date.replace(' ', '-').capitalize() # Date may be 'In-press' etc. } key_format = u'%s' % self.context['key_format'] key = key_format.format(**replacements) key = self.context['key_clean_regex'].sub('', key) return key
def clean(self, string): string = compat_str( string) # Cast as a unicode string in python 2 or 3 string = self.html_regex.sub('', string) # Remove any html formatting # Clean and return (based on field cleaning replacements in Zoteros BibLatex.js) return self.clean_regex.sub('', string)
def clean(self, string): string = compat_str(string) # Cast as a unicode string in python 2 or 3 return self.html_regex.sub('', string) # Remove any html formatting
def get_info(self): # Retrieve information about date, publication, volume, issue and # title self.cur.execute(self.info_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: key = item[3] self.index[item_id].key = key item_name = item[1] item_value = item[2] if item_name == u"date": self.index[item_id].date = self.parse_date(item) elif item_name == u"publicationTitle": self.index[item_id].publication = compat_str(item_value) elif item_name == u"publisher": self.index[item_id].publisher = item_value elif item_name == u"language": self.index[item_id].language = item_value elif item_name == u"DOI": self.index[item_id].doi = item_value elif item_name == u"ISBN": self.index[item_id].isbn = item_value elif item_name == u"volume": self.index[item_id].volume = item_value elif item_name == u"issue": self.index[item_id].issue = item_value elif item_name == u"pages": self.index[item_id].pages = item_value elif item_name == u"url": self.index[item_id].url = item_value elif item_name == u"title": self.index[item_id].title = item_value elif item_name == u"abstractNote": self.index[item_id].abstract = item_value # Retrieve author information self.cur.execute(self.author_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: item_lastname = item[1] item_firstname = item[2] self.index[item_id].authors.append([item_lastname ,item_firstname]) # Retrieve collection information self.cur.execute(self.collection_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: item_collection = item[1] self.index[item_id].collections.append(item_collection) # Retrieve tag information self.cur.execute(self.tag_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: item_tag = item[1] self.index[item_id].tags.append(item_tag) # Retrieve note information self.cur.execute(self.note_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: item_note = item[1] self.index[item_id].notes.append(item_note) # Retrieve attachments self.cur.execute(self.attachment_query) for item in self.cur.fetchall(): item_id = item[0] if item_id in self.index: if item[1] != None: att = item[1] # If the attachment is stored in the Zotero folder, it is preceded # by "storage:" if att[:8] == u"storage:": item_attachment = att[8:] # The item attachment appars to be encoded in # latin-1 encoding, which we don't want, so recode. item_attachment = item_attachment.encode('latin-1').decode('utf-8') attachment_id = item[2] if item_attachment[-4:].lower() in self.attachment_ext: self.cur.execute( \ u"select items.key from items where itemID = %d" \ % attachment_id) key = self.cur.fetchone()[0] self.index[item_id].fulltext.append(os.path.join( \ self.storage_path, key, item_attachment)) # If the attachment is linked, it is simply the full # path to the attachment else: item_attachment = att.encode('latin-1').decode('utf-8') self.index[item_id].fulltext.append(item_attachment) self.cur.close()