Esempio n. 1
0
 def test_pages(self):
     self.assertEqual(BibTeX._bibtex_to_csl_pages('313'), Pages(first=313))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('12+'), Pages(first=12))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('1--3'), Pages(first=1,
                                                                 last=3))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('1-3'), Pages(first=1,
                                                                last=3))
Esempio n. 2
0
 def test_pages(self):
     self.assertEqual(BibTeX._bibtex_to_csl_pages('313'), Pages(first=313))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('12+'), Pages(first=12))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('1--3'),
                      Pages(first=1, last=3))
     self.assertEqual(BibTeX._bibtex_to_csl_pages('1-3'),
                      Pages(first=1, last=3))
Esempio n. 3
0
 def test_date_months(self):
     for january in ['jan', 'JAN', '01']:
         self.assertEqual(BibTeX._parse_month(january), ({'month': 1}, ) * 2)
     self.assertEqual(BibTeX._parse_month("10~jan"),
                      ({'month': 1, 'day': 10}, ) * 2)
     self.assertEqual(BibTeX._parse_month("jul~4"),
                      ({'month': 7, 'day': 4}, ) * 2)
Esempio n. 4
0
 def test_date_months(self):
     for january in ['jan', 'JAN', '01']:
         self.assertEqual(BibTeX._parse_month(january), ({'month': 1}, ) * 2)
     self.assertEqual(BibTeX._parse_month("10~jan"),
                      ({'month': 1, 'day': 10}, ) * 2)
     self.assertEqual(BibTeX._parse_month("jul~4"),
                      ({'month': 7, 'day': 4}, ) * 2)
Esempio n. 5
0
def bibToCite(bibfile, ID):
    bib_source = BibTeX(bibfile)

    style_path = get_style_filepath('modern-language-association')
    bib_style = CitationStylesStyle(style_path, validate=False)

    bibliography = CitationStylesBibliography(bib_style, bib_source,
                                              formatter.plain)

    citation1 = Citation([CitationItem(ID)])

    bibliography.register(citation1)

    with open('out.txt', 'w') as f:
        for item in bibliography.bibliography():
            print(str(item), file=f)
Esempio n. 6
0
def get_bib():
    bib_source = BibTeX('notebooks/bibliography.bib', encoding='utf8')
    bib_style = CitationStylesStyle('notebooks/springer.csl', validate=False)

    bibliography = CitationStylesBibliography(bib_style, bib_source,
                                              formatter.html)
    bib_cites = [Citation([CitationItem(item)]) for item in bib_source]

    for item in bib_cites:
        bibliography.register(item)
    for item in bib_cites:
        bibliography.cite(item, _cite_warn)

    num = len(bibliography.keys)
    bib_entries = dict()
    for i in range(num):
        bib = ''.join(bibliography.bibliography()[i])
        # remove beginning digits and \. from bib entries
        bib = '{}. ' + re.sub("^\d+\.", "", bib)
        bib_entries[bibliography.keys[i]] = bib

    return bib_entries
Esempio n. 7
0
print('\n' * 100)

# Get all items in the ISAW Zotero
library_id = os.getenv('LIBRARY_ID')
library_type = os.getenv('LIBRARY_TYPE')
api_key = os.getenv('API_KEY')

z = zotero.Zotero(library_id, library_type, api_key)
# vItems = z.everything(z.top(sort="dateModified"))
# vItems = z.top(sort="dateModified", limit=10)
bibTeX = z.top(sort="dateModified", limit=10, format='bibtex')

# Save it and reopen it, because the documentation doesn't describe a way to load a string
with open('bibtex.bib', 'w') as bibtex_file:
    bibtexparser.dump(bibTeX, bibtex_file)
bib_source = BibTeX('bibtex.bib', encoding='utf-8')

# load a CSL style
fCSL = open('static/csl/mla-isawbib-full.csl', "rb")
fCSL = open('static/csl/mla-isawbib-authorless.csl', "rb")
bib_style = CitationStylesStyle(fCSL, validate=False)

# Create the citeproc-py bibliography, passing it the:
# * CitationStylesStyle,
# * BibliographySource (CiteProcJSON in this case), and
# * a formatter (plain, html, or you can write a custom formatter)

bibliography = CitationStylesBibliography(bib_style, bib_source,
                                          formatter.html)

# Processing citations in a document needs to be done in two passes as for some
Esempio n. 8
0
# -*- coding: utf-8 -*-

import time

before_time = time.clock()
from rfic2009style import RFIC2009Paper
from citeproc.source.bibtex import BibTeX
after_time = time.clock()
import_time = after_time - before_time
print('Module import time: {:.2f} seconds'.format(import_time))

before_time = time.clock()
bib_source = BibTeX('references.bib')
doc = RFIC2009Paper('template.xml', bib_source)
after_time = time.clock()
setup_time = after_time - before_time
print('Setup time: {:.2f} seconds'.format(setup_time))

before_time = time.clock()
doc.render('template')
after_time = time.clock()
render_time = after_time - before_time
print('Render time: {:.2f} seconds ({:.2f}s per page)'.format(
    render_time, render_time / doc.page_count))

total_time = import_time + setup_time + render_time
print('Total time: {:.2f} seconds'.format(total_time))
Esempio n. 9
0
#!/usr/bin/env python

# The references are parsed from a BibTeX database, so we import the
# corresponding parser.
from citeproc.source.bibtex import BibTeX

# Import the citeproc-py classes we'll use below.
from citeproc import CitationStylesStyle, CitationStylesBibliography
from citeproc import formatter
from citeproc import Citation, CitationItem


# Parse the BibTeX database.

bib_source = BibTeX('xampl.bib')


# load a CSL style (from the current directory)

bib_style = CitationStylesStyle('harvard1', validate=False)


# Create the citeproc-py bibliography, passing it the:
# * CitationStylesStyle,
# * BibliographySource (BibTeX in this case), and
# * a formatter (plain, html, or you can write a custom formatter)

bibliography = CitationStylesBibliography(bib_style, bib_source,
                                          formatter.plain)

Esempio n. 10
0
 def test(bibtex, csl):
     self.assertEqual(BibTeX._bibtex_to_csl_pages(bibtex), csl)
Esempio n. 11
0
 def test(bibtex, csl):
     self.assertEqual(BibTeX._bibtex_to_csl_pages(bibtex), csl)
Esempio n. 12
0
#!/usr/bin/env python

# The references are parsed from a BibTeX database, so we import the
# corresponding parser.
from citeproc.source.bibtex import BibTeX

# Import the citeproc-py classes we'll use below.
from citeproc import CitationStylesStyle, CitationStylesBibliography
from citeproc import formatter
from citeproc import Citation, CitationItem

# Parse the BibTeX database.

bib_source = BibTeX('mylibrary.bib')

# load a CSL style (from the current directory)

bib_style = CitationStylesStyle('harvard1', validate=False)

# Create the citeproc-py bibliography, passing it the:
# * CitationStylesStyle,
# * BibliographySource (BibTeX in this case), and
# * a formatter (plain, html, or you can write a custom formatter)

bibliography = CitationStylesBibliography(bib_style, bib_source,
                                          formatter.plain)

# Processing citations in a document needs to be done in two passes as for some
# CSL styles, a citation can depend on the order of citations in the
# bibliography and thus on citations following the current one.
# For this reason, we first need to register all citations with the
Esempio n. 13
0
 def _get_source(self, data):
     """Get source data object for citeproc-py."""
     if self.record_format == 'csl':
         return CiteProcJSON([json.loads(data)])
     elif self.record_format == 'bibtex':
         return BibTeX(data)
Esempio n. 14
0
            f.write(unicode(str(i)) + '. ')
            i = i + 1
        f.write(unicode(str(item)) + '\n')
    f.close()


def write_to_bbl(filename, bibliography):
    f = open(filename, 'w', encoding='utf8')
    f.write('\\begin{thebibliography}{}\n')
    i = 0
    for item in bibliography.bibliography():
        f.write('\\bibitem{' + my_cities[i] + '}')
        f.write(unicode(str(item)) + '\n')
        i = i + 1
    f.write('\\end{thebibliography}')
    f.close()


bib_source = BibTeX('literature.bib', encoding='utf8')
bib_style = CitationStylesStyle('gost-r-7-0-5-2008',
                                locale='ru-RU',
                                validate=False)
bibliography = CitationStylesBibliography(bib_style, bib_source,
                                          formatter.plain)

get_cities('literature.bib')
for i in range(len(my_cities)):
    bibliography.register(Citation([CitationItem(my_cities[i])]))

write_to_txt('my_bibliography.txt', bibliography)
write_to_bbl('my_bibliography.bbl', bibliography)
    outfile.close()
    from citeproc.py2compat import *

    from citeproc.source.bibtex import BibTeX

    from citeproc import CitationStylesStyle, CitationStylesBibliography
    from citeproc import formatter
    from citeproc import Citation, CitationItem

    print(bibFilename + "\n")
    file = open(bibFilename, "r+", encoding="utf-8")
    string = file.read()

    print("\n\n" + string + "\n\n")
    file.close()
    bib_source = BibTeX(bibFilename)

    ######################################################################################################
    ######################################################################################################
    #######     This is the locally included Chicago style template, included in ciceproc/data/styles
    bib_style = CitationStylesStyle('chicago-annotated-bibliography',
                                    validate=False)

    # Create the citeproc-py bibliography, passing it the:
    # * CitationStylesStyle,
    # * BibliographySource (BibTeX in this case), and
    # * a formatter (plain, html, or you can write a custom formatter)

    bibliography = CitationStylesBibliography(bib_style, bib_source,
                                              formatter.html)
    ######################################################################################################