示例#1
0
def get_url_csl_item_zotero(url):
    """
    Use Zotero's translation-server to generate a CSL Item for the specified URL.
    """
    from manubot.cite.zotero import export_as_csl, web_query

    zotero_data = web_query(url)
    csl_data = export_as_csl(zotero_data)
    (csl_item,) = csl_data
    return csl_item
示例#2
0
def get_url_csl_item_zotero(url: str) -> CSLItem:
    """
    Use Zotero's translation-server to generate a CSL Item for the specified URL.
    """
    from manubot.cite.zotero import export_as_csl, web_query

    zotero_data = web_query(url)
    csl_data = export_as_csl(zotero_data)
    (csl_item, ) = csl_data
    if not csl_item.get("URL"):
        # some Zotero translators don't set URL. https://github.com/manubot/manubot/issues/244
        csl_item["URL"] = url
    return csl_item
示例#3
0
def test_web_query_returns_single_result_pubmed_url():
    """
    See test_web_query_returns_single_result_legacy_manubot_url docstring.
    ```
    curl \
      --header "Content-Type: text/plain" \
      --data 'https://www.ncbi.nlm.nih.gov/pubmed/?term=sci-hub%5Btitle%5D' \
      'https://translate.manubot.org/web?single=1'
    ```
    """
    url = "https://www.ncbi.nlm.nih.gov/pubmed/?term=sci-hub%5Btitle%5D"
    zotero_metadata = web_query(url)
    assert isinstance(zotero_metadata, list)
    assert len(zotero_metadata) == 1
    (zotero_metadata,) = zotero_metadata
    assert zotero_metadata["title"].startswith("sci-hub[title]")
示例#4
0
def test_web_query():
    """
    The translation-server web endpoint can be tested via curl:
    ```
    curl \
      --header "Content-Type: text/plain" \
      --data 'https://bigthink.com/neurobonkers/a-pirate-bay-for-science' \
      'https://translate.manubot.org/web'
    ```
    An outdated installation of translation-server caused the web query for this
    URL to be extraordinarily slow but has now been fixed. See
    https://github.com/zotero/translation-server/issues/63
    """
    url = "https://bigthink.com/neurobonkers/a-pirate-bay-for-science"
    zotero_data = web_query(url)
    assert isinstance(zotero_data, list)
    assert len(zotero_data) == 1
    assert zotero_data[0]["title"].startswith("Meet the Robin Hood of Science")
示例#5
0
def test_web_query_returns_single_result_legacy_manubot_url():
    """
    Check that single=1 is specified for web queries. Without this, Zotero
    can prefer translators that return multiple choices. This occurs with legacy
    Manubot mansucripts, which get assigned the DOI translator as top priority.
    https://github.com/zotero/translation-server/issues/65
    ```
    curl \
      --header "Content-Type: text/plain" \
      --data 'https://greenelab.github.io/scihub-manuscript/v/cfe599e25405d38092bf972b6ea1c9e0dcf3deb9/' \
      'https://translate.manubot.org/web?single=1'
    ```
    """
    url = 'https://greenelab.github.io/scihub-manuscript/v/cfe599e25405d38092bf972b6ea1c9e0dcf3deb9/'
    zotero_metadata = web_query(url)
    assert isinstance(zotero_metadata, list)
    assert len(zotero_metadata) == 1
    zotero_metadata, = zotero_metadata
    assert zotero_metadata[
        'title'] == 'Sci-Hub provides access to nearly all scholarly literature'