File: _doitotex.py

package info (click to toggle)
isbnlib 3.9.3-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster
  • size: 596 kB
  • sloc: python: 4,575; makefile: 4
file content (25 lines) | stat: -rw-r--r-- 579 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
"""Return metadata, of a given DOI, formated as BibTeX."""

import logging

from .dev.webservice import query

LOGGER = logging.getLogger(__name__)

URL = 'http://dx.doi.org/{DOI}'
UA = 'isbnlib (gzip)'


def doi2tex(doi):
    """Get the bibtex ref for doi."""
    data = query(
        URL.format(DOI=doi),
        user_agent=UA,
        appheaders={
            'Accept': 'application/x-bibtex; charset=utf-8',
        })
    if not data:  # pragma: no cover
        LOGGER.warning('no data return for doi: %s', doi)
        return None
    return data