summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-03-19 15:45:21 -0700
committerBryan Newbold <bnewbold@robocracy.org>2019-03-19 15:45:21 -0700
commitd9f9a84957913f0ddd878bb079b423c059b4c81d (patch)
treec69b4fc9f4aeaf6f85002bc4db05c0ce4d547e49
parenta712cf6a8732ba11d393b80e28b4fc487362ea00 (diff)
downloadfatcat-d9f9a84957913f0ddd878bb079b423c059b4c81d.tar.gz
fatcat-d9f9a84957913f0ddd878bb079b423c059b4c81d.zip
update enrich examples demo script
-rw-r--r--extra/demo_entities/enrich_examples.py112
1 files changed, 63 insertions, 49 deletions
diff --git a/extra/demo_entities/enrich_examples.py b/extra/demo_entities/enrich_examples.py
index 9b74a954..a97263b9 100644
--- a/extra/demo_entities/enrich_examples.py
+++ b/extra/demo_entities/enrich_examples.py
@@ -5,6 +5,7 @@ This file started life as an ipython log file
Ugh, it needs to be copied to ../../python (with ./files/) to actually run. Derp.
"""
+import os
import datetime
import fatcat_client
from fatcat_client.rest import ApiException
@@ -14,11 +15,15 @@ from fatcat_tools import *
import datetime
# setup env
-admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae"
-local_conf = fatcat_client.Configuration()
-local_conf.host = 'http://localhost:9411/v0'
-local_api = fatcat_client.DefaultApi(fatcat_client.ApiClient(local_conf))
-api = local_api
+#admin_id = "aaaaaaaaaaaabkvkaaaaaaaaae"
+#local_conf = fatcat_client.Configuration()
+#local_conf.host = 'http://localhost:9411/v0'
+#local_api = fatcat_client.DefaultApi(fatcat_client.ApiClient(local_conf))
+#api = local_api
+api = authenticated_api(
+ 'http://localhost:9411/v0',
+ # token is an optional kwarg (can be empty string, None, etc)
+ token=os.environ.get("FATCAT_API_AUTH_TOKEN"))
def upsert_release(doi, fname):
"""
@@ -46,16 +51,16 @@ def upsert_release(doi, fname):
files = [f for f in r.files]
print("bootstrapping release: {}".format(doi))
- eg = api.create_editgroup(Editgroup(editor_id=admin_id))
- resp = api.create_release(r, editgroup=eg.id)
+ eg = api.create_editgroup(Editgroup())
+ resp = api.create_release(r, editgroup_id=eg.editgroup_id)
for f in files:
f.ident = None
f.revision = None
- f.releases = [resp.ident]
- files_resp = api.create_file_batch(files, editgroup=eg.id)
+ f.release_ids = [resp.ident]
+ files_resp = api.create_file_batch(files, editgroup_id=eg.editgroup_id)
- api.accept_editgroup(eg.id)
+ api.accept_editgroup(eg.editgroup_id)
return resp.ident
def upsert_container(issnl, fname):
@@ -75,17 +80,17 @@ def upsert_container(issnl, fname):
c.edit_extra = dict(source="copied from old production as a demo")
print("bootstrapping container: {}".format(issnl))
- eg = api.create_editgroup(Editgroup(editor_id=admin_id))
- resp = api.create_container(c, editgroup=eg.id)
- api.accept_editgroup(eg.id)
+ eg = api.create_editgroup(Editgroup())
+ resp = api.create_container(c, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
return resp.ident
def math_universe():
- c_ident = upsert_container("0015-9018", "files/foundations_of_physics.json")
+ #c_ident = upsert_container("0015-9018", "files/foundations_of_physics.json")
ident = upsert_release("10.1007/s10701-007-9186-9", "files/math_universe.json")
base = api.get_release(ident, expand="files")
- base.container_id = c_ident
+ #base.container_id = c_ident
files = [api.get_file(f.ident) for f in base.files]
@@ -100,20 +105,29 @@ def math_universe():
preprint.revision = None
preprint.doi = None
preprint.container = None
+ preprint.publisher = None
+ preprint.volume = None
+ preprint.pages = None
+ preprint.wikidata_qid = None
+ preprint.arxiv_id = "0704.0646v2"
preprint.container_id = None
- preprint.extra = dict(arxiv=dict(id='0704.0646v2', section='gr-qc'))
+ preprint.extra = dict(arxiv=dict(section='gr-qc'))
preprint.release_date = datetime.date(2007, 10, 8)
- preprint.release_status = 'preprint'
+ preprint.release_status = 'submitted'
preprint.work_id = base.work_id
- eg = api.create_editgroup(Editgroup(editor_id=admin_id))
- resp = api.create_release(preprint, editgroup=eg.id)
- files[1].releases = [resp.ident]
- files[2].releases = [resp.ident]
- api.update_file(files[1].ident, files[1], editgroup=eg.id)
- api.update_file(files[2].ident, files[2], editgroup=eg.id)
- api.update_release(base.ident, base, editgroup=eg.id)
- api.accept_editgroup(eg.id)
+ eg = api.create_editgroup(Editgroup(description="math universe pre-print and file assignment"))
+ resp = api.create_release(preprint, editgroup_id=eg.editgroup_id)
+ files[1].release_ids = [resp.ident]
+ files[2].release_ids = [resp.ident]
+ files[3].release_ids = []
+ files[4].release_ids = []
+ api.update_file(files[1].ident, files[1], editgroup_id=eg.editgroup_id)
+ api.update_file(files[2].ident, files[2], editgroup_id=eg.editgroup_id)
+ api.update_file(files[3].ident, files[3], editgroup_id=eg.editgroup_id)
+ api.update_file(files[4].ident, files[4], editgroup_id=eg.editgroup_id)
+ api.update_release(base.ident, base, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
# ok, that seems to have split it well enough
# Next, a distill.pub work
@@ -123,46 +137,46 @@ def distill_pub():
# april 4, 2017
# Gabriel Goh
# orcid: 0000-0001-5021-2683
- c_ident = upsert_container("2476-0757", "files/distill_pub.json")
+ #c_ident = upsert_container("2476-0757", "files/distill_pub.json")
ident = upsert_release("10.23915/distill.00006", "files/distill_momentum.json")
momentum_works = api.get_release(ident, expand="files")
- eg = api.create_editgroup(Editgroup(editor_id=admin_id))
- goh = CreatorEntity(display_name="Gabriel Goh", orcid="0000-0001-5021-2683")
- goh = api.create_creator(goh, editgroup=eg.id)
+ eg = api.create_editgroup(Editgroup(description="distill article enrichment"))
+ #goh = CreatorEntity(display_name="Gabriel Goh", orcid="0000-0001-5021-2683")
+ #goh = api.create_creator(goh, editgroup_id=eg.editgroup_id)
#distill = ContainerEntity(name="Distill", issnl="2476-0757", publisher="Distill", wikidata_qid="Q36437840")
- #distill = api.create_container(distill, editgroup=eg.id)
- momentum_works.abstracts = [ReleaseEntityAbstracts(mimetype="text/plain", lang="eng", content="We often think of Momentum as a means of dampening oscillations and speeding up the iterations, leading to faster convergence. But it has other interesting behavior. It allows a larger range of step-sizes to be used, and creates its own oscillations. What is going on?")]
- momentum_works.contribs = [ReleaseContrib(raw_name="Gabriel Goh", role='author', index=0, creator_id=goh.ident)]
- momentum_works = api.update_release(momentum_works.ident, momentum_works, editgroup=eg.id)
- momentum_works.container_id = c_ident
+ #distill = api.create_container(distill, editgroup_id=eg.editgroup_id)
+ momentum_works.abstracts = [ReleaseEntityAbstracts(mimetype="text/plain", lang="en", content="We often think of Momentum as a means of dampening oscillations and speeding up the iterations, leading to faster convergence. But it has other interesting behavior. It allows a larger range of step-sizes to be used, and creates its own oscillations. What is going on?")]
+ #momentum_works.contribs = [ReleaseContrib(raw_name="Gabriel Goh", role='author', index=0, creator_id=goh.ident)]
+ momentum_works = api.update_release(momentum_works.ident, momentum_works, editgroup_id=eg.editgroup_id)
+ #momentum_works.container_id = c_ident
momentum_page = FileEntity(sha1='e3dfd05f151eea10f438c3b9756ca9bd23ecf3d5', mimetype='text/html')
momentum_page.urls = [FileEntityUrls(url="https://distill.pub/2017/momentum/", rel="publisher"), FileEntityUrls(url="http://web.archive.org/web/20180613072149/https://distill.pub/2017/momentum/", rel="webarchive")]
- momentum_page.releases = [momentum_works.ident]
- api.create_file(momentum_page, editgroup=eg.id)
- api.accept_editgroup(eg.id)
+ momentum_page.release_ids = [momentum_works.ident]
+ api.create_file(momentum_page, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
def dlib_example():
# and now a d-lib exammple
- c_ident = upsert_container("1082-9873", "files/dlib.json")
+ #c_ident = upsert_container("1082-9873", "files/dlib.json")
ident = upsert_release("10.1045/november14-jahja", "files/dlib_example.json")
dlib = api.get_release(ident)
- eg = api.create_editgroup(Editgroup(editor_id=admin_id, description="enriching d-lib article"))
- authors = [api.create_creator(CreatorEntity(display_name=a.raw_name), editgroup=eg.id) for a in dlib.contribs]
- for i in range(3):
- dlib.contribs[i].creator_id = authors[i].ident
- dlib.container_id = c_ident
- r = api.update_release(dlib.ident, dlib, editgroup=eg.id)
+ eg = api.create_editgroup(Editgroup(description="enriching d-lib article"))
+ #authors = [api.create_creator(CreatorEntity(display_name=a.raw_name), editgroup_id=eg.editgroup_id) for a in dlib.contribs]
+ #for i in range(3):
+ # dlib.contribs[i].creator_id = authors[i].ident
+ #dlib.container_id = c_ident
+ #r = api.update_release(dlib.ident, dlib, editgroup_id=eg.editgroup_id)
dlib_page = FileEntity(sha1='a637f1d27d9bcb237310ed29f19c07e1c8cf0aa5', mimetype='text/html')
dlib_page.urls = [FileEntityUrls(url="http://www.dlib.org/dlib/november14/jahja/11jahja.html", rel="publisher"), FileEntityUrls(url="http://web.archive.org/web/20180602033542/http://www.dlib.org/dlib/november14/jahja/11jahja.html", rel="webarchive")]
- dlib_page.releases = [dlib.ident]
- api.create_file(dlib_page, editgroup=eg.id)
- api.accept_editgroup(eg.id)
+ dlib_page.release_ids = [dlib.ident]
+ api.create_file(dlib_page, editgroup_id=eg.editgroup_id)
+ api.accept_editgroup(eg.editgroup_id)
# TODO: the actual web file here?
math_universe()
-distill_pub()
-dlib_example()
+#distill_pub()
+#dlib_example()