Skip to content
Snippets Groups Projects
Commit a7694263 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

handle preprint as well

parent 7ab28824
No related branches found
No related tags found
1 merge request!224Resolve "Rework references"
Pipeline #124491 canceled with stages
in 2 minutes and 13 seconds
...@@ -22,7 +22,7 @@ def fetch_articles_from_zotero( ...@@ -22,7 +22,7 @@ def fetch_articles_from_zotero(
format="csljson", format="csljson",
limit=batch_size, limit=batch_size,
start=i, start=i,
itemType="journalArticle", # itemType="journalArticle",
sort="title", sort="title",
)["items"] )["items"]
for item in items: for item in items:
...@@ -39,12 +39,79 @@ def add_articles_to_zotero_from_doi(doi, key): ...@@ -39,12 +39,79 @@ def add_articles_to_zotero_from_doi(doi, key):
res = cr.works(ids=[doi]) res = cr.works(ids=[doi])
zot = zotero.Zotero("5151022", "group", key) zot = zotero.Zotero("5151022", "group", key)
itemtype = "journalArticle"
# pyzotero grabs the template dict from the server # pyzotero grabs the template dict from the server
zitem = zot.item_template(itemtype)
# console.print(zitem) # console.print(zitem)
message = res["message"] 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)
# console.print(message["title"]) # console.print(message["title"])
zitem["title"] = message["title"][0] zitem["title"] = message["title"][0]
if "page" in message: if "page" in message:
...@@ -73,41 +140,10 @@ def add_articles_to_zotero_from_doi(doi, key): ...@@ -73,41 +140,10 @@ def add_articles_to_zotero_from_doi(doi, key):
if key in message: if key in message:
zitem[key] = message[key] 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] items_to_add = [zitem]
zot.check_items(items_to_add) zot.check_items(items_to_add)
res = zot.create_items(items_to_add) res = zot.create_items(items_to_add)
# console.print(res)
new_item = res["successful"]["0"] new_item = res["successful"]["0"]
zot.addto_collection("BSWL96X3", new_item) zot.addto_collection("BSWL96X3", new_item)
console.print(f"add doi {doi}") console.print("[green]done")
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment