PKRHeЙ&mendeley2biblatex/library_converter.pyimport sqlite3 import sys from .bib_entry import BibEntry def dict_factory(cursor, row): """A function to use the SQLite row as dict for string formatting""" d = {} for idx, col in enumerate(cursor.description): if row[idx]: d[col[0]] = row[idx] else: d[col[0]] = '' return d class LibraryConverter: @staticmethod def convert_library(db_name, bibtex_file=sys.stdout, quiet=False, folder=None): """Converts Mendely SQlite database to BibTeX file @param db_name The Mendeley SQlite file @param bibtex_file The BibLaTeX file to output the bibliography, if not supplied the output is written to the system standard stdout. @param quiet If true do not show warnings and errors @param folder If provided the Rult gets filtered by folder name """ db = sqlite3.connect(db_name) c = db.cursor() # c.row_factory = sqlite3.Row # CANNOT be used with unicode string formatting # since it expect str indexes, and we are using # unicode string... grrr... ascii is not dead c.row_factory = dict_factory # allows to use row (entry) as a dict with # unicode keys. if sys.stdout != bibtex_file: f = open(bibtex_file, 'w') f.write("""This file was generated automatically by Mendeley To BibLaTeX python script.\n\n""") else: f = bibtex_file query = ''' SELECT D.id, D.citationKey, D.title, D.type, D.doi, D.publisher, D.publication, D.volume, D.issue, D.institution, D.month, D.year, D.pages, D.revisionNumber AS number, D.sourceType, DU.url, D.dateAccessed AS urldate FROM Documents D LEFT JOIN DocumentCanonicalIds DCI ON D.id = DCI.documentId LEFT JOIN DocumentFiles DF ON D.id = DF.documentId LEFT JOIN DocumentUrls DU ON DU.documentId = D.id LEFT JOIN DocumentFolders DFO ON D.id = DFO.documentId LEFT JOIN Folders FO ON DFO.folderId = FO.id WHERE D.confirmed = "true" AND D.deletionPending= "false" ''' if folder is not None: query += 'AND FO.name="' + folder + '"' query += ''' GROUP BY D.citationKey ORDER BY D.citationKey ;''' for entry in c.execute(query): c2 = db.cursor() c2.execute(''' SELECT lastName, firstNames FROM DocumentContributors WHERE documentId = ? ORDER BY id''', (entry['id'],)) authors_list = c2.fetchall() authors = [] for author in authors_list: authors.append(', '.join(author)) entry['authors'] = ' and '.join(authors) if isinstance(entry['url'],bytes): entry['url'] = entry['url'].decode('UTF-8') BibEntry.clean_characters(entry) # If you need to add more templates: # all types of templates are available at # http://www.cs.vassar.edu/people/priestdo/tips/bibtex # all avaliable types are described in biblatex documentation # ftp://ftp.mpi-sb.mpg.de/pub/tex/mirror/ftp.dante.de/pub/tex/macros/latex/contrib/biblatex/doc/biblatex.pdf try: formatted_entry = BibEntry.TEMPLATES.get(entry['type']).format( entry=entry) except AttributeError: if not quiet: print('''Unhandled entry type {0}, please add your own template.'''.format( entry['type'])) continue f.write(formatted_entry) if sys.stdout != bibtex_file: f.close() PKPH?mendeley2biblatex/__init__.pyimport sys from argparse import ArgumentParser from mendeley2biblatex.library_converter import LibraryConverter __all__ = ["bib_entry", "library_converter"] def main(): """Set this script some command line options. See usage.""" parser = ArgumentParser(description='Convert a sqlite database from mendeley to bibetex') # usage: %prog [-o out.bib] mendeley.sqlite''', version='%prog ' + version) parser.add_argument('-q', '--quiet', action='store_true', default=False, dest='quiet', help='Do not display any information.') parser.add_argument('-f', '--folder', default=None, dest='folder', help='Limit output to mendeley folder') parser.add_argument("-o", "--output", dest="bibtex_file", default=sys.stdout, help="BibTeX file name, else output will be printed to stdout") parser.add_argument('input', metavar='INPUT_FILE', nargs='?', help='the mendeley database') args = parser.parse_args() if not args.input: parser.error('''No file specified''') LibraryConverter.convert_library(args.input, args.bibtex_file, args.quiet, args.folder) if __name__ == "__main__": try: main() except KeyboardInterrupt: print('Interrupted by user') PKNH)cs mendeley2biblatex/bib_entry.pyclass BibEntry: TEMPLATES = { 'JournalArticle': ''' @article{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", journal = "{entry[publication]}", number = "{entry[issue]}", volume = "{entry[volume]}", pages = "{entry[pages]}", year = "{entry[year]}", doi = "{entry[doi]}", }}''', 'ConferenceProceedings': ''' @proceedings{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", publisher = "{entry[publisher]}", pages = "{entry[pages]}", year = "{entry[year]}", doi = "{entry[doi]}", }}''', 'WebPage': ''' @online{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", year = "{entry[year]}", url = "{entry[url]}", urldate = "{entry[urldate]}" }}''', 'Book': ''' @book{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", publisher = "{entry[publisher]}", year = "{entry[year]}", pages = "{entry[pages]}", volume = "{entry[volume]}", doi = "{entry[doi]}", }}''', 'BookSection': ''' @inbook{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", booktitle = "{entry[publication]}", publisher = "{entry[publisher]}", year = "{entry[year]}", volume = "{entry[volume]}", pages = "{entry[pages]}", doi = "{entry[doi]}", url = "{entry[url]}", urldate = "{entry[urldate]}" }}''', 'Patent': ''' @thesis{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", number = "{entry[number]}", year = "{entry[year]}", type = "{entry[sourceType]}", doi = "{entry[doi]}", url = "{entry[url]}", urldate = "{entry[urldate]}" }}''', 'Report': ''' @inbook{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", type = "{entry[publication]}" institution = "{entry[institution]}", year = "{entry[year]}", type = "{entry[sourceType]}", doi = "{entry[doi]}", pages = "{entry[pages]}", url = "{entry[url]}", urldate = "{entry[urldate]}" }}''', 'Thesis': ''' @thesis{{{entry[citationKey]}, author = "{entry[authors]}", title = "{entry[title]}", institution = "{entry[institution]}", year = "{entry[year]}", type = "{entry[sourceType]}", doi = "{entry[doi]}", pages = "{entry[pages]}", url = "{entry[url]}", urldate = "{entry[urldate]}" }}''' } @staticmethod def clean_characters(entry): """A helper function to convert special characters to LaTeX characters""" # List of char and replacement, add your own list below char_to_replace = { # LaTeX special char '&': '\&', # UTF8 not understood by inputenc '–': '--', # utf8 2014, special dash '—': '--', # utf8 2013, special dash '∕': '/', # utf8 2215, math division 'κ': 'k', # Greek kappa '×': 'x', # times } # Which field shall we check and convert entry_key = ['publisher', 'publication', 'title'] for k in entry_key: for char, repl_char in char_to_replace.items(): entry[k] = entry[k].replace(char, repl_char) PK&SH>Mv{1mendeley2biblatex-0.1.4.dist-info/DESCRIPTION.rst================= Mendeley2Biblatex ================= This package converts a mendeley database to a biblatex file It is based on a `script `_ written by François Bianco, University of Geneva Installation ------------ pip install mendeley2biblatex Usage ----- First locate your database. On Linux systems it is: ls ~/.local/share/data/Mendeley\ Ltd./Mendeley\Desktop/your@email.com@www.mendeley.com.sqlite The package only reads your database, but to avoid any loss it is **recommended** to work on a copy of your database Then run mendeley2biblatex on your file with mendeley2bibtex -o mendeley.bib mendeley.sqlite To see all options use mendeley2biblatex -h PK&SHxK>>2mendeley2biblatex-0.1.4.dist-info/entry_points.txt[console_scripts] mendeley2biblatex = mendeley2biblatex:main PK&SH/mendeley2biblatex-0.1.4.dist-info/metadata.json{"classifiers": ["Development Status :: 3 - Alpha", "Intended Audience :: Science/Research", "Topic :: Utilities", "Topic :: Scientific/Engineering", "Topic :: Text Processing :: General", "Environment :: Console", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5"], "extensions": {"python.commands": {"wrap_console": {"mendeley2biblatex": "mendeley2biblatex:main"}}, "python.details": {"contacts": [{"email": "dev@lioman.de", "name": "Lioman", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/lioman/mendeley2biblatex"}}, "python.exports": {"console_scripts": {"mendeley2biblatex": "mendeley2biblatex:main"}}}, "generator": "bdist_wheel (0.26.0)", "keywords": ["mendeley", "latex", "biblatex", "bibtex", "biber"], "license": "GNU General Public License v3 or later (GPLv3+)", "metadata_version": "2.0", "name": "mendeley2biblatex", "summary": "A tool to convert your Mendeley to a biblatex library", "version": "0.1.4"}PK&SHu7/mendeley2biblatex-0.1.4.dist-info/top_level.txtmendeley2biblatex PK&SH}\\'mendeley2biblatex-0.1.4.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py3-none-any PK&SH&}OO*mendeley2biblatex-0.1.4.dist-info/METADATAMetadata-Version: 2.0 Name: mendeley2biblatex Version: 0.1.4 Summary: A tool to convert your Mendeley to a biblatex library Home-page: https://github.com/lioman/mendeley2biblatex Author: Lioman Author-email: dev@lioman.de License: GNU General Public License v3 or later (GPLv3+) Keywords: mendeley latex biblatex bibtex biber Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Science/Research Classifier: Topic :: Utilities Classifier: Topic :: Scientific/Engineering Classifier: Topic :: Text Processing :: General Classifier: Environment :: Console Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 ================= Mendeley2Biblatex ================= This package converts a mendeley database to a biblatex file It is based on a `script `_ written by François Bianco, University of Geneva Installation ------------ pip install mendeley2biblatex Usage ----- First locate your database. On Linux systems it is: ls ~/.local/share/data/Mendeley\ Ltd./Mendeley\Desktop/your@email.com@www.mendeley.com.sqlite The package only reads your database, but to avoid any loss it is **recommended** to work on a copy of your database Then run mendeley2biblatex on your file with mendeley2bibtex -o mendeley.bib mendeley.sqlite To see all options use mendeley2biblatex -h PK&SH.(mendeley2biblatex-0.1.4.dist-info/RECORDmendeley2biblatex/__init__.py,sha256=kyzR1enymNsDqyUy13Wvn2Iirxd4uwH1rveaSDJ2sRc,1245 mendeley2biblatex/bib_entry.py,sha256=z8AfJ8hDjNInWOyUAzLCvLsIzgM5-Or69yxwbXnYGgA,3563 mendeley2biblatex/library_converter.py,sha256=45IEMhYwlFsKERan4FY9uYMAjeLt_VVmYSdr2yBsqKw,3993 mendeley2biblatex-0.1.4.dist-info/DESCRIPTION.rst,sha256=rAFdN-7xWLV2RIcK4Z7LHRMGJ2IP6XYCIiESQNrB81I,733 mendeley2biblatex-0.1.4.dist-info/METADATA,sha256=qjsMLfW6FEvYYX_UPeMhpp1Tt2WrTzHwXvn_7PGWiAM,1615 mendeley2biblatex-0.1.4.dist-info/RECORD,, mendeley2biblatex-0.1.4.dist-info/WHEEL,sha256=zX7PHtH_7K-lEzyK75et0UBa3Bj8egCBMXe1M4gc6SU,92 mendeley2biblatex-0.1.4.dist-info/entry_points.txt,sha256=eYyFV7kFy-wwM_a7X_n41P1JWkMXqMoN87lTG61Kh5A,62 mendeley2biblatex-0.1.4.dist-info/metadata.json,sha256=F0aj57qXIj_fuSzn0B3mNti7ARo8F6zC2AAu2xNRuA0,1179 mendeley2biblatex-0.1.4.dist-info/top_level.txt,sha256=NVRBcUvsodzhm0YdwXOQfPlrCpMd9EtJ4v4j2kYZZC0,18 PKRHeЙ&mendeley2biblatex/library_converter.pyPKPH?mendeley2biblatex/__init__.pyPKNH)cs mendeley2biblatex/bib_entry.pyPK&SH>Mv{1#mendeley2biblatex-0.1.4.dist-info/DESCRIPTION.rstPK&SHxK>>2H&mendeley2biblatex-0.1.4.dist-info/entry_points.txtPK&SH/&mendeley2biblatex-0.1.4.dist-info/metadata.jsonPK&SHu7/+mendeley2biblatex-0.1.4.dist-info/top_level.txtPK&SH}\\',mendeley2biblatex-0.1.4.dist-info/WHEELPK&SH&}OO*,mendeley2biblatex-0.1.4.dist-info/METADATAPK&SH.(U3mendeley2biblatex-0.1.4.dist-info/RECORDPK g=7