diff --git a/packages/df-wiki-cli/df_wiki_cli/articles/__init__.py b/packages/df-wiki-cli/df_wiki_cli/articles/__init__.py index 9b4fed681bc93dd94c4c3a9920a231bfd47d91dc..fd164cd545f265db7320a0850f1d6503a6276f9c 100644 --- a/packages/df-wiki-cli/df_wiki_cli/articles/__init__.py +++ b/packages/df-wiki-cli/df_wiki_cli/articles/__init__.py @@ -22,7 +22,7 @@ def fetch_articles_from_zotero( format="csljson", limit=batch_size, start=i, - itemType="journalArticle", + # itemType="journalArticle", sort="title", )["items"] for item in items: @@ -39,12 +39,79 @@ def add_articles_to_zotero_from_doi(doi, key): res = cr.works(ids=[doi]) zot = zotero.Zotero("5151022", "group", key) - itemtype = "journalArticle" + # pyzotero grabs the template dict from the server - zitem = zot.item_template(itemtype) + # console.print(zitem) message = res["message"] + console.print(f"add doi {doi}, type {message['type']}") + if message["type"] == "posted-content": + # { + # "itemType": "Preprint", + # "title": "", + # "creators": [{"creatorType": "author", "firstName": "", "lastName": ""}], + # "abstractNote": "", + # "genre": "", + # "repository": "", + # "archiveID": "", + # "place": "", + # "date": "", + # "series": "", + # "seriesNumber": "", + # "DOI": "", + # "citationKey": "", + # "url": "", + # "accessDate": "", + # "archive": "", + # "archiveLocation": "", + # "shortTitle": "", + # "language": "", + # "libraryCatalog": "", + # "callNumber": "", + # "rights": "", + # "extra": "", + # "tags": [], + # "collections": [], + # "relations": {}, + # } + itemtype = "Preprint" + elif message["type"] == "journal-article": + # { + # 'itemType': 'journalArticle', + # 'title': '', + # 'creators': [{'creatorType': 'author', 'firstName': '', 'lastName': ''}], + # 'abstractNote': '', + # 'publicationTitle': '', + # 'volume': '', + # 'issue': '', + # 'pages': '', + # 'date': '', + # 'series': '', + # 'seriesTitle': '', + # 'seriesText': '', + # 'journalAbbreviation': '', + # 'language': '', + # 'DOI': '', + # 'ISSN': '', + # 'shortTitle': '', + # 'url': '', + # 'accessDate': '', + # 'archive': '', + # 'archiveLocation': '', + # 'libraryCatalog': '', + # 'callNumber': '', + # 'rights': '', + # 'extra': '', + # 'tags': [], + # 'collections': [], + # 'relations': {} + # } + itemtype = "journalArticle" + else: + raise NotImplementedError(f"type {message['type']} need to be implemented") + zitem = zot.item_template(itemtype) # console.print(message) + # console.print(message["title"]) zitem["title"] = message["title"][0] if "page" in message: @@ -73,41 +140,10 @@ def add_articles_to_zotero_from_doi(doi, key): if key in message: zitem[key] = message[key] - # { - # 'itemType': 'journalArticle', - # 'title': '', - # 'creators': [{'creatorType': 'author', 'firstName': '', 'lastName': ''}], - # 'abstractNote': '', - # 'publicationTitle': '', - # 'volume': '', - # 'issue': '', - # 'pages': '', - # 'date': '', - # 'series': '', - # 'seriesTitle': '', - # 'seriesText': '', - # 'journalAbbreviation': '', - # 'language': '', - # 'DOI': '', - # 'ISSN': '', - # 'shortTitle': '', - # 'url': '', - # 'accessDate': '', - # 'archive': '', - # 'archiveLocation': '', - # 'libraryCatalog': '', - # 'callNumber': '', - # 'rights': '', - # 'extra': '', - # 'tags': [], - # 'collections': [], - # 'relations': {} - # } - items_to_add = [zitem] + zot.check_items(items_to_add) res = zot.create_items(items_to_add) - # console.print(res) new_item = res["successful"]["0"] zot.addto_collection("BSWL96X3", new_item) - console.print(f"add doi {doi}") + console.print("[green]done")