aboutsummaryrefslogtreecommitdiffstats
path: root/fatcat/api_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'fatcat/api_client.py')
-rw-r--r--fatcat/api_client.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/fatcat/api_client.py b/fatcat/api_client.py
index 291b7a1b..f2fd6a1d 100644
--- a/fatcat/api_client.py
+++ b/fatcat/api_client.py
@@ -144,6 +144,31 @@ class FatCatApiClient:
assert rv.status_code == 200
release_id = rv.json()['id']
+ def import_issn_file(self, json_file, create_containers=False, batchsize=100):
+ eg = self.new_editgroup()
+ i = 0
+ with open(json_file, 'r') as file:
+ for line in file:
+ if i % batchsize == 0:
+ sys.stdout.write('\n{}: '.format(i))
+ if (i+1) % 20 == 0:
+ sys.stdout.write('.')
+ i = i + 1
+ obj = json.loads(line)
+ if not ("author" in obj and "title" in obj):
+ continue
+ try:
+ self.import_crossref_dict(obj, editgroup=eg,
+ create_containers=create_containers)
+ except Exception as e:
+ print("ERROR: {}".format(e))
+ if i % batchsize == 0:
+ self.accept_editgroup(eg)
+ eg = self.new_editgroup()
+ if i % batchsize != 0:
+ self.accept_editgroup(eg)
+ print("done!")
+
def health(self):
rv = self.get("/health")
assert rv.status_code == 200