Exemplo n.º 1
0
def test_export_as_csl():
    """
    CSL export can be tested via curl:
    ```
    curl \
      --header "Content-Type: application/json" \
      --data '[{"key": "IN22XN53", "itemType": "webpage", "date": "2016-02-09T20:12:00"}]' \
      'https://translate.manubot.org/export?format=csljson'
    ```
    """
    zotero_data = [
        {
            "key": "IN22XN53",
            "version": 0,
            "itemType": "webpage",
            "creators": [],
            "tags": [],
            "title": "Meet the Robin Hood of Science",
            "websiteTitle": "Big Think",
            "date": "2016-02-09T20:12:00",
            "url": "https://bigthink.com/neurobonkers/a-pirate-bay-for-science",
            "abstractNote": "How one researcher created a pirate bay for science more powerful than even libraries at top universities.",
            "language": "en",
            "accessDate": "2018-12-06T20:10:14Z",
        }
    ]
    csl_item = export_as_csl(zotero_data)[0]
    assert csl_item["title"] == "Meet the Robin Hood of Science"
    assert csl_item["container-title"] == "Big Think"
Exemplo n.º 2
0
def get_isbn_csl_item_zotero(isbn):
    """
    Generate CSL JSON Data for an ISBN using Zotero's translation-server.
    """
    from manubot.cite.zotero import export_as_csl, search_query
    zotero_data = search_query(f'isbn:{isbn}')
    csl_data = export_as_csl(zotero_data)
    csl_item, = csl_data
    return csl_item
Exemplo n.º 3
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
Exemplo n.º 4
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