Exemple #1
0
def main(argv=None):
    parser = argparse.ArgumentParser(
        description='Converts Zotero RDF to BibTeX.')
    parser.add_argument(
        'infile',
        type=argparse.FileType('r'),
        nargs='?',
        default=sys.stdin,
        help='Input Zotero RDF file (default: read from standard input)')
    parser.add_argument(
        'outfile',
        type=argparse.FileType('w'),
        nargs='?',
        default=sys.stdout,
        help='Output BibTeX file (default: write to standard output)')
    parser.add_argument('--biber',
                        action='store_true',
                        help="Use Biber's extensions to BibTeX format")
    parser.add_argument(
        '--abbreviations',
        action='store_true',
        help=
        'Put the journal abbreviation in the "journal" field instead of in the "abbrev" field'
    )
    parser.add_argument(
        '--acronyms',
        action='store_true',
        help=
        'Try to detect acronyms in titles and surround them with \\zoteroacronym'
    )
    parser.add_argument('--version',
                        action='version',
                        version='Zotero2BibTeX version 0')
    args = parser.parse_args()

    latex.register()

    if args.biber:
        biber_update_types()

    g = rdflib.ConjunctiveGraph()
    g.load(args.infile)

    # Iterate over all the items in the bibliography
    bibitems = [
        process_item(g, s, use_biber=args.biber)
        for s, o in g.subject_objects(zotero['itemType'])
        if g.value(subject=s, predicate=zotero['itemType']) != 'attachment'
    ]

    # Generate unique keys for each item according to my personal style
    generate_keys(bibitems)

    for bibitem in bibitems:
        args.outfile.write(
            bibitem.bibtex_string(use_biber=args.biber,
                                  use_abbrevs=args.abbreviations,
                                  detect_acronyms=args.acronyms))

    return 0
def main(argv=None):
    parser = argparse.ArgumentParser(description='Converts Zotero RDF to BibTeX.')
    parser.add_argument('infile',
        type=argparse.FileType('r'),
        nargs='?',
        default=sys.stdin,
        help='Input Zotero RDF file (default: read from standard input)')
    parser.add_argument('outfile',
        type=argparse.FileType('w'),
        nargs='?',
        default=sys.stdout,
        help='Output BibTeX file (default: write to standard output)')
    parser.add_argument('--biber',
        action='store_true',
        help="Use Biber's extensions to BibTeX format")
    parser.add_argument('--abbreviations',
        action='store_true',
        help='Put the journal abbreviation in the "journal" field instead of in the "abbrev" field')
    parser.add_argument('--acronyms',
        action='store_true',
        help='Try to detect acronyms in titles and surround them with \\zoteroacronym')
    parser.add_argument('--version',
        action='version',
        version='Zotero2BibTeX version 0')
    args = parser.parse_args()

    latex.register()

    if args.biber:
        biber_update_types()

    g = rdflib.ConjunctiveGraph()
    g.load(args.infile)

    # Iterate over all the items in the bibliography
    bibitems = [process_item(g, s, use_biber=args.biber)
        for s, o in g.subject_objects(zotero['itemType'])
        if g.value(subject=s, predicate=zotero['itemType']) != 'attachment']

    # Generate unique keys for each item according to my personal style
    generate_keys(bibitems)

    for bibitem in bibitems:
        args.outfile.write(bibitem.bibtex_string(
            use_biber=args.biber,
            use_abbrevs=args.abbreviations,
            detect_acronyms=args.acronyms))

    return 0
Exemple #3
0
"""
Set of routines to parse bibtex data and return each entry as a dictionary
It is mainly intended as a helper file to the Class BibItem (see bibitem.py)
but can be used as a standalone script

USAGE:
  strings,db = parsefile(bibtexfile)

"""


import sys
import re,string
import codecs
import latex
latex.register()

import helper

reg_pages=re.compile(r'\W+')

def process_pages(pages):
  """ Returns a 2-tuple (firstpage,lastpage) from a string"""
  pp=reg_pages.split(pages)
  firstpage=pp[0]
  if len(pp)==2:    lastpage=pp[1]
  else:             lastpage=''
  return firstpage,lastpage

def bibtexauthor(data):
  """ Returns a list of authors where each author is a list of the form:
Exemple #4
0
# -*- coding: utf-8 -*-

# ../bin/anth2bib.py > all.bib

# reads all .xml files in current directory
# and prints bibtex entries to stdout

import os
import re, sys
import xml.etree.ElementTree as ET
import codecs
# file latex.py should be in the same directory as this python script
import latex

# register latex as a codec
latex.register()


# convert xml entry to string
def author_string(author):
    author_s = ""
    if (author.findall("last") and author.find("last").text):
        author_s += author.find("last").text
    if (author.findall("first") and author.find("first").text):
        author_s += ", " + author.find("first").text
    # should not have quotes in names
    if re.search(r"\"", author_s):
        sys.stderr.write("warning: quotes in name: " + author_s + "\n")
        author_s = re.sub(r"\"", "''", author_s)
    # convert accents to latex escapes
    author_str = codecs.encode(author_s, "latex")