|
1 | 1 | #! /usr/bin/env python3 |
2 | | -# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +import os |
| 4 | +import shutil |
3 | 5 |
|
4 | 6 | import click |
| 7 | + |
5 | 8 | import papis.cli |
6 | 9 | import papis.api |
| 10 | +import papis.logging |
7 | 11 | from papis.commands.export import run as export |
8 | | -import os |
9 | | -import shutil |
10 | | -import logging |
11 | 12 |
|
12 | | -logger = logging.getLogger('papis-html') |
13 | | -logging.basicConfig(level=logging.INFO) |
| 13 | +logger = papis.logging.get_logger("papis_html") |
14 | 14 |
|
15 | 15 | template_folder = os.path.join( |
16 | 16 | os.path.dirname(os.path.abspath(__file__)), |
17 | | - 'data' |
| 17 | + "data" |
18 | 18 | ) |
19 | 19 |
|
| 20 | + |
20 | 21 | @click.command() |
21 | 22 | @papis.cli.query_option() |
22 | | -@click.help_option('-h', '--help') |
| 23 | +@click.help_option("-h", "--help") |
23 | 24 | @click.option( |
24 | | - '-o', '--out', |
25 | | - help='Output directory', |
26 | | - default='bibliography' |
| 25 | + "-o", "--out", |
| 26 | + help="Output directory", |
| 27 | + default="html" |
27 | 28 | ) |
28 | | -def main(query, out): |
| 29 | +def main(query: str, out: str) -> None: |
29 | 30 | """ |
30 | | - Create a simple searchable offline html site with your references |
| 31 | + Create a simple searchable offline HTML site with your documents |
31 | 32 | """ |
32 | 33 |
|
33 | | - logger.info('Searching in database..'.format(out)) |
| 34 | + logger.info("Searching in database.") |
34 | 35 | docs = papis.api.get_documents_in_lib( |
35 | 36 | library=papis.api.get_lib_name(), |
36 | 37 | search=query |
37 | 38 | ) |
38 | 39 |
|
39 | | - logger.info('Saving in folder {}'.format(out)) |
40 | | - bibtex_text = export(docs, to_format='bibtex') |
| 40 | + bibtex_text = export(docs, to_format="bibtex") |
41 | 41 |
|
42 | | - logger.info('template files in {}'.format(template_folder)) |
43 | | - shutil.copytree( |
44 | | - template_folder, |
45 | | - out |
46 | | - ) |
| 42 | + shutil.copytree(template_folder, out) |
| 43 | + logger.info("Template files copied from '%s'", template_folder) |
| 44 | + logger.info("Saving in folder '%s'.", out) |
47 | 45 |
|
48 | | - bibtex_outfile = os.path.join(out, 'library.bib') |
49 | | - logger.info('Creating bib file in {}'.format(bibtex_outfile)) |
50 | | - with open(bibtex_outfile, 'w+') as fd: |
| 46 | + bibtex_outfile = os.path.join(out, "papis-html-library.bib") |
| 47 | + with open(bibtex_outfile, "w+") as fd: |
51 | 48 | fd.write(bibtex_text) |
52 | 49 |
|
53 | | - logger.info('Done!') |
54 | | - |
55 | | -if __name__ == "__main__": |
56 | | - main() |
| 50 | + logger.info("Created BibTex file: '%s'.", bibtex_outfile) |
0 commit comments