commonmeta-py 0.109__py3-none-any.whl → 0.111__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
commonmeta/__init__.py CHANGED
@@ -10,7 +10,7 @@ commonmeta-py is a Python library to convert scholarly metadata
10
10
  """
11
11
 
12
12
  __title__ = "commonmeta-py"
13
- __version__ = "0.109"
13
+ __version__ = "0.111"
14
14
  __author__ = "Martin Fenner"
15
15
  __license__ = "MIT"
16
16
 
commonmeta/cli.py CHANGED
@@ -205,6 +205,7 @@ def push(
205
205
  login_passwd=login_passwd,
206
206
  host=host,
207
207
  token=token,
208
+ legacy_key=legacy_key,
208
209
  prefix=prefix,
209
210
  )
210
211
  end = time.time()
commonmeta/metadata.py CHANGED
@@ -394,6 +394,7 @@ class MetadataList:
394
394
  # options needed for InvenioRDM registration
395
395
  self.host = kwargs.get("host", None)
396
396
  self.token = kwargs.get("token", None)
397
+ self.legacy_key = kwargs.get("legacy_key", None)
397
398
 
398
399
  self.items = self.read_metadata_list(wrap(meta.get("items", None)), **kwargs)
399
400
  self.errors = [i.errors for i in self.items if i.errors is not None]
@@ -489,7 +490,7 @@ class MetadataList:
489
490
  elif to == "datacite":
490
491
  raise ValueError("Datacite not yet supported for metadata lists")
491
492
  elif to == "inveniordm":
492
- response = push_inveniordm_list(self, host=self.host, token=self.token)
493
+ response = push_inveniordm_list(self, host=self.host, token=self.token, legacy_key=self.legacy_key)
493
494
  return response
494
495
  else:
495
496
  raise ValueError("No valid output format found")
@@ -1,6 +1,7 @@
1
1
  """InvenioRDM writer for commonmeta-py"""
2
2
 
3
3
  import re
4
+ from time import time
4
5
  from typing import Optional
5
6
  from urllib.parse import urlparse
6
7
 
@@ -370,7 +371,7 @@ def write_inveniordm_list(metalist):
370
371
  return [write_inveniordm(item) for item in metalist.items]
371
372
 
372
373
 
373
- def push_inveniordm(metadata, host: str, token: str):
374
+ def push_inveniordm(metadata, host: str, token: str, legacy_key:str):
374
375
  """Push record to InvenioRDM"""
375
376
 
376
377
  record = {}
@@ -462,18 +463,23 @@ def push_inveniordm(metadata, host: str, token: str):
462
463
  record = add_record_to_community(
463
464
  record, host, token, path_parts[2]
464
465
  )
466
+
467
+ # optionally update rogue-scholar legacy record
468
+ if host == "rogue-scholar.org" and legacy_key is not None:
469
+ record = update_legacy_record(record, legacy_key)
470
+
465
471
  except Exception as e:
466
472
  raise InvenioRDMError(f"Unexpected error: {str(e)}")
467
473
 
468
474
  return record
469
475
 
470
476
 
471
- def push_inveniordm_list(metalist, host: str, token: str) -> list:
477
+ def push_inveniordm_list(metalist, host: str, token: str, legacy_key:str) -> list:
472
478
  """Push inveniordm list to InvenioRDM, returns list of push results."""
473
479
 
474
480
  if metalist is None:
475
481
  return None
476
- items = [push_inveniordm(item, host, token) for item in metalist.items]
482
+ items = [push_inveniordm(item, host, token, legacy_key) for item in metalist.items]
477
483
  return json.dumps(items, option=json.OPT_INDENT_2)
478
484
 
479
485
 
@@ -571,6 +577,7 @@ def publish_draft_record(record, host, token):
571
577
  )
572
578
  response.raise_for_status()
573
579
  data = response.json()
580
+ record["uuid"] = py_.get(data, "metadata.identifiers.0.identifier")
574
581
  record["created"] = data.get("created", None)
575
582
  record["updated"] = data.get("updated", None)
576
583
  record["status"] = "published"
@@ -597,6 +604,56 @@ def add_record_to_community(record, host, token, community_id):
597
604
  raise InvenioRDMError(f"Error adding record to community: {str(e)}")
598
605
 
599
606
 
607
+ def update_legacy_record(record, legacy_key: str):
608
+ """Update corresponding record in Rogue Scholar legacy database."""
609
+
610
+ legacy_host = "bosczcmeodcrajtcaddf.supabase.co"
611
+
612
+ if not legacy_key:
613
+ return record, ValueError("no legacy key provided")
614
+
615
+ if not record.get("uuid", None):
616
+ return record, ValueError("no UUID provided")
617
+
618
+ now = f"{int(time())}"
619
+
620
+ if not record.get("doi", None):
621
+ return ValueError("no valid doi to update")
622
+
623
+ output = {
624
+ "doi": record["doi"],
625
+ "indexed_at": now,
626
+ "indexed": "true",
627
+ "archived": "true"
628
+ }
629
+
630
+ request_url = f"https://{legacy_host}/rest/v1/posts?id=eq.{record['uuid']}"
631
+
632
+ headers = {
633
+ "Content-Type": "application/json",
634
+ "apikey": legacy_key,
635
+ "Authorization": f"Bearer {legacy_key}",
636
+ "Prefer": "return=minimal"
637
+ }
638
+
639
+ try:
640
+ response = requests.patch(
641
+ request_url,
642
+ json=output,
643
+ headers=headers,
644
+ timeout=30
645
+ )
646
+ response.raise_for_status()
647
+ if response.status_code != 204:
648
+ return record, Exception(f"Unexpected status code: {response.status_code}")
649
+
650
+ record["status"] = "updated_legacy"
651
+ return record
652
+
653
+ except requests.exceptions.RequestException as e:
654
+ return record, e
655
+
656
+
600
657
  def search_by_slug(slug, type_value, host, token) -> Optional[str]:
601
658
  """Search for a community by slug in InvenioRDM"""
602
659
  headers = {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commonmeta-py
3
- Version: 0.109
3
+ Version: 0.111
4
4
  Summary: Library for conversions to/from the Commonmeta scholarly metadata format
5
5
  Project-URL: Homepage, https://python.commonmeta.org
6
6
  Project-URL: Repository, https://github.com/front-matter/commonmeta-py
@@ -1,13 +1,13 @@
1
- commonmeta/__init__.py,sha256=eCm4N0guNRBzN4Im8n0_ekLtRbDLxTR7tWXpkL56enM,2098
1
+ commonmeta/__init__.py,sha256=7VbnWhd_GpuWNLnOiFnEkdZ7RLRMCJviElrUM9gDfuA,2098
2
2
  commonmeta/api_utils.py,sha256=y5KLfIOWOjde7LXZ36u-eneQJ-Q53yXUZg3hWpCBS2E,2685
3
3
  commonmeta/author_utils.py,sha256=3lYW5s1rOUWNTKs1FP6XLfEUY3yCLOe_3L_VdJTDMp0,8585
4
4
  commonmeta/base_utils.py,sha256=-MGy9q2uTiJEkPWQUYOJMdq-3tRpNnvBwlLjvllQ5g8,11164
5
- commonmeta/cli.py,sha256=OALbEqHaLO2L8KdzKqW4N1VpKqvtCKbfQkCTPevQWxA,8449
5
+ commonmeta/cli.py,sha256=pdBpBosLNq3RS9buO-Voqawc9Ay1eSt-xP5O97iOft4,8480
6
6
  commonmeta/constants.py,sha256=wSTEUiHeRdXLwjXEQD9AU2hxFyEKi5OTX2iHOKO6nF0,19844
7
7
  commonmeta/date_utils.py,sha256=H2cCobX0JREIUOT_cCigGd3MG7prGiQpXk1m4ZNrFwU,6318
8
8
  commonmeta/doi_utils.py,sha256=ZztajfOLtnASk1BbQ1Y2Q4B_xxlnbujn7Opx5a1U5vY,9582
9
9
  commonmeta/file_utils.py,sha256=tGvXxScjh-PPo5YvLDyk4sqwY5Q50N0zAmBHVaUOLeU,3268
10
- commonmeta/metadata.py,sha256=TF1BHS7R56xBNc84JhKE5-sysNNgd-n_cX4pXGG75sE,18778
10
+ commonmeta/metadata.py,sha256=k_u2ZE2_GbCQrzAPms5ywa2ylQ-GrEYJIRTQpPAMHGw,18863
11
11
  commonmeta/schema_utils.py,sha256=WGpmMj9cfNMg_55hhgwY9qpO0A1HSvTLQC2equjBftI,1770
12
12
  commonmeta/translators.py,sha256=CBMK4jrXRmGZiAhCh6wsJjhbDJWbcsda8UvXFXxccAw,1363
13
13
  commonmeta/utils.py,sha256=pJnh3EzOU1E2nutnAZsopY_NsUX6zYmxoj5bIYqqWvE,50574
@@ -80,11 +80,11 @@ commonmeta/writers/commonmeta_writer.py,sha256=QpfyhG__7o_XpsOTCPWxGymO7YKwZi2LQ
80
80
  commonmeta/writers/crossref_xml_writer.py,sha256=d-Rb2Vd_g3UW8GM4APIT7fivSQ5GMssZ6Ubi3OykHaw,33479
81
81
  commonmeta/writers/csl_writer.py,sha256=4gDYs1EzK4_L2UIRTfs25wgHmYRwdRP2zmfxF9387oU,2779
82
82
  commonmeta/writers/datacite_writer.py,sha256=bcinpwhq7XnVthKHH8-sdXA34dSlvFH4ImYH768iaQU,6428
83
- commonmeta/writers/inveniordm_writer.py,sha256=eflpF45PGLkA6K2zhaYWS6Y93a3yiHSG8OIUtpocYx8,21791
83
+ commonmeta/writers/inveniordm_writer.py,sha256=LbBM0gLGsvoujp1dV_9JYBda2Ehl6naRww99e4mxF24,23475
84
84
  commonmeta/writers/ris_writer.py,sha256=3SdyEvMRaPRP1SV1MB-MXBlunE7x6og7RF1zuWtetPc,2094
85
85
  commonmeta/writers/schema_org_writer.py,sha256=s18_x0ReXwAGBoEAwp2q-HCgFQ-h5qRg6JyAlqCoSFE,5871
86
- commonmeta_py-0.109.dist-info/METADATA,sha256=DheK6f5msYFDlxE8n2RXxOfcWTXuIWykoDiyrgE9wQo,7652
87
- commonmeta_py-0.109.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
- commonmeta_py-0.109.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
- commonmeta_py-0.109.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
- commonmeta_py-0.109.dist-info/RECORD,,
86
+ commonmeta_py-0.111.dist-info/METADATA,sha256=jhSXxau6pUwREEMi9NvmCk7GgkYly-MdRWhQ2Zh-5wc,7652
87
+ commonmeta_py-0.111.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
+ commonmeta_py-0.111.dist-info/entry_points.txt,sha256=U4w4BoRuS3rN5t5Y-uYSyOeU5Lh_VRVMS9OIDzIgw4w,50
89
+ commonmeta_py-0.111.dist-info/licenses/LICENSE,sha256=wsIvxF9Q9GC9vA_s79zTWP3BkXJdfUNRmALlU8GbW1s,1074
90
+ commonmeta_py-0.111.dist-info/RECORD,,