def bibtex_reader(self, bibtextdata): """ Parse the bibtex data Arguments: bibtextdata {str} -- bibtexdata Returns: list -- list of all entries of the bibtex """ parser = BibTexParser() parser.ignore_nonstandard_types = False parser.homogenise_fields = False parser.common_strings = False bib_database = bibtexparser.loads(bibtextdata, parser) return bib_database.entries[0]
def main(): args = _args() bibfile = args.input_bib with open(bibfile) as bibtex_file: parser = BibTexParser() parser.ignore_nonstandard_types = False parser.homogenize_fields = True parser.common_strings = True parser.customization = keep_uppercase bib_database = bibtexparser.load(bibtex_file, parser=parser) if args.clean: for entry in bib_database.entries: for k in ('file', 'annote', 'abstract', 'url', 'file', 'link'): entry.pop(k, None) for entry in bib_database.entries: entry['title'] = '{{{}}}'.format(entry['title']) bibwriter = BibTexWriter() with open(args.output_bib, 'w') as outbib: bibtexparser.dump(bib_database, outbib, bibwriter)
""" Draft zero of code to read Dave's Refs.bib file and allow search and pdf viewing """ import bibtexparser import subprocess import sys from bibtexparser.bparser import BibTexParser from bibtexparser.bwriter import BibTexWriter from bibtexparser.bibdatabase import BibDatabase # Failed #import bibtexparser.bibtexexpression.BibtexExpression as be #be.set_string_name_parse_action(None) parser = BibTexParser(interpolate_strings=False) parser.ignore_nonstandard_types = False # ? parser.common_strings = True #parser.interpolate_strings = False # None homedir = '/home/davids/' texdir = homedir + 'Documents/D_Articles/' testr = 'Documents/TeX/testr.bib' testr = 'Documents/TeX/fixed.testr.bib' # fixtext2 testr = homedir + 'Documents/TeX/Refs.bib' test_export = False # True def query_user(): search_terms = input('Give search terms:') # eg QQDEP, 2014 search_terms = search_terms.split()
from habanero import Crossref import pandas as pd import bibtexparser from bibtexparser.bparser import BibTexParser import datetime work = Crossref() parser = BibTexParser() parser.ignore_nonstandard_types = False parser.homogenise_fields = False parser.common_strings = False # This list contains words that are not decisive to identify the publications, # such as articles and adverbs. They must be removed because the Crossref # API retrieves all the publications whose titles that have at least a word # in common with the publication under analysis common_words = ['a','the','on','an','for','of','at','with', 'without', 'toward', 'towards', 'not', 'but', 'in', 'is', 'are', 'that', 'and', 'or', 'learning','into','to','its','which','do','does','using','via', 'from'] def doisearcher(origtitle, inauthor): """ This function calls the Crossref API and returns the most relevant publications whose title has at least one word in common with the input title (origtitle). This list is limited to the first 1000 entries. It is possible to run the search on the list of authors. In this version, this option is commented out. :param origtitle: title of the input publication :param inauthor: list of authors of the input publication :return: the list of the matched publications (w2) and the title of the
@STRING{ apr = "apr"} @STRING{ may = "may"} @STRING{ jun = "jun"} @STRING{ jul = "jul"} @STRING{ aug = "aug"} @STRING{ sep = "sep"} @STRING{ oct = "oct"} @STRING{ nov = "nov"} @STRING{ dec = "dec"} """ print 'Parsing files in '+folder+'/' for file in os.listdir(folder): if file.endswith(".bib"): print(os.path.join(folder, file)) with open(os.path.join(folder, file)) as bibtex_file: content = Months + bibtex_file.read() parser = BibTexParser() parser.common_strings = True bib_database = bibtexparser.loads(content, parser) for entry in bib_database.entries: #print(entry['ID']) entry['keywords'] = entry.get('keywords', '') if(entry['keywords'] != ''): entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0] + ', ' + entry['keywords'] else: entry['keywords'] = 'cleBib/' + entry['ID'] + ', article/' + os.path.splitext(file)[0] with open(os.path.join(folder+'-clean', file), 'w') as bibtex_export: bibtex_export_str = bibtexparser.dumps(bib_database, writer) bibtex_export.write(bibtex_export_str.encode('utf8'))