Skip to content

Commit

Permalink
Merge pull request #3 from caltechlibrary/main
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
RohanBhattaraiNP authored Nov 8, 2024
2 parents 005d9cb + faa360a commit ed93fa8
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 105 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/codemeta2cff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CodeMeta2CFF
run-name: Run CodeMeta2CFF after ${{github.event_name}} by ${{github.actor}}

on:
push:
paths: ['codemeta.json']
workflow_dispatch:
inputs:
reason:
description: 'Reason'
required: false
default: 'Manual trigger'

jobs:
CodeMeta2CFF:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Convert CFF
uses: caltechlibrary/codemeta2cff@main
- name: Commit CFF
uses: EndBug/add-and-commit@v9
with:
message: 'Add updated CITATION.cff from codemeta.json file'
add: 'CITATION.cff'
99 changes: 68 additions & 31 deletions .github/workflows/iga.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
name: InvenioRDM GitHub Archiver and CodeMeta2CFF
env:
INVENIO_SERVER: https://data.caltech.edu

Expand All @@ -10,47 +9,51 @@ env:
parent_record: "6qhkm-7n074"
debug: false

# ~~~~~~~~~~ The rest of this file should be left as-is ~~~~~~~~~~
# This variable is a setting for post-archiving CodeMeta file updates.
# If you don't have a CodeMeta file, you can remove the add_doi_codemeta
# and Coremeta2CFF jobs at the bottom of this file.
ref: main

# ╭────────────────────────────────────────────╮
# │ The rest of this file should be left as-is │
# ╰────────────────────────────────────────────╯

name: InvenioRDM GitHub Archiver
on:
release:
types: [published]
workflow_dispatch:
inputs:
release_tag:
description: "The tag of the release to archive:"
description: The release tag (empty = latest)
parent_record:
description: ID of parent record (for versioning)
community:
description: Name of InvenioRDM community (if any)
draft:
default: false
description: "Mark the record as a draft:"
description: Mark the record as a draft
type: boolean
all_assets:
default: false
description: "Attach all GitHub assets:"
description: Attach all GitHub assets
type: boolean
all_metadata:
default: false
description: "Include additional GitHub metadata:"
community:
description: "Send record to InvenioRDM community:"
parent_record:
description: "ID of parent record (for versioning):"
description: Include additional GitHub metadata
type: boolean
debug:
description: Print debug info in the GitHub log
type: boolean

run-name: Archive ${{inputs.release_tag || 'latest release'}} in InvenioRDM
jobs:
CodeMeta2CFF:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Convert CFF
uses: caltechlibrary/codemeta2cff@main
- name: Commit CFF
uses: EndBug/add-and-commit@v9
with:
message: 'Add CITATION.cff for release'
add: "['CITATION.cff']"
push: origin HEAD:main
run_iga:
name: "Send to ${{needs.get_repository.outputs.server}}"
name: Send to ${{needs.get_repository.outputs.server}}
runs-on: ubuntu-latest
needs: [get_repository, CodeMeta2CFF]
needs: get_repository
outputs:
record_doi: ${{steps.iga.outputs.record_doi}}
steps:
- uses: caltechlibrary/iga@main
- uses: caltechlibrary/iga@v1
id: iga
with:
INVENIO_SERVER: ${{env.INVENIO_SERVER}}
INVENIO_TOKEN: ${{secrets.INVENIO_TOKEN}}
Expand All @@ -62,10 +65,44 @@ jobs:
parent_record: ${{github.event.inputs.parent_record || env.parent_record}}
release_tag: ${{github.event.inputs.release_tag || 'latest'}}
get_repository:
name: "Get repository name"
name: Get repository name
runs-on: ubuntu-latest
outputs:
server: ${{steps.parse.outputs.host}}
steps:
- id: parse
- name: Extract name from INVENIO_SERVER
id: parse
run: echo "host=$(cut -d'/' -f3 <<< ${{env.INVENIO_SERVER}} | cut -d':' -f1)" >> $GITHUB_OUTPUT
add_doi_codemeta:
name: "Add ${{needs.run_iga.outputs.record_doi}} to codemeta.json"
needs: run_iga
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.ref }}
- name: Install sde
run: pip install sde
- name: Add DOI to CodeMeta File
run: sde identifier ${{needs.run_iga.outputs.record_doi}} codemeta.json
- name: Commit CFF
uses: EndBug/add-and-commit@v9
with:
message: 'Add DOI to codemeta.json file'
add: 'codemeta.json'
CodeMeta2CFF:
runs-on: ubuntu-latest
needs: add_doi_codemeta
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.ref }}
- name: Convert CFF
uses: caltechlibrary/codemeta2cff@main
- name: Commit CFF
uses: EndBug/add-and-commit@v9
with:
message: 'Add updated CITATION.cff from codemeta.json file'
add: 'CITATION.cff'
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ authors:
abstract: Python wrapper for CaltechDATA API.
repository-code: "https://github.com/caltechlibrary/caltechdata_api"
type: software
version: 1.8.1
version: 1.8.2
license-url: "https://data.caltech.edu/license"
keywords:
- GitHub
- metadata
- software
- InvenioRDM
date-released: 2024-10-18
date-released: 2024-11-06
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CaltechDATA API Python Library

[![DOI](https://img.shields.io/badge/dynamic/json.svg?label=DOI&query=$.pids.doi.identifier&uri=https://data.caltech.edu/api/records/wfjr5-kw507/versions/latest)](https://data.caltech.edu/records/wfjr5-kw507/latest)

The `caltechdata_api` Python library provides a convenient interface for interacting with the CaltechDATA API. It allows users to write files, create DataCite 4 standard JSON records, edit existing records, and retrieve metadata from the CaltechDATA repository.

## Features
Expand Down
7 changes: 5 additions & 2 deletions caltechdata_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def get_or_set_token(production=True):
with open(token_file, "rb") as f:
encrypted_token = f.read()
token = decrypt_token(encrypted_token, key)
print(
"Using saved CaltechDATA production token."
if production
else "Using saved CaltechDATA test token."
)
return token
except FileNotFoundError:
while True:
Expand Down Expand Up @@ -422,8 +427,6 @@ def main():

def create_record(production):
token = get_or_set_token(production)
# keep_file = input("Do you want to keep your existing files? (yes/no): ").lower() == "yes"
print("Using CaltechDATA token:", token)
while True:
choice = get_user_input(
"Do you want to use metadata from an existing file or create new metadata? (existing/create): "
Expand Down
3 changes: 1 addition & 2 deletions caltechdata_api/customize_schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Convert a DataCite 4 or 4.3 standard schema json record to the customized internal
# schema used by TIND in CaltechDATA
# Convert a DataCite 4.3 standard schema json record to the InvenioRDM schema
import argparse
import json
from datetime import date
Expand Down
37 changes: 29 additions & 8 deletions caltechdata_api/get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,43 @@


def get_metadata(
idv, production=True, validate=True, emails=False, schema="43", token=False
idv,
production=True,
validate=True,
emails=False,
schema="43",
token=False,
authors=False,
):
# Returns just DataCite metadata or DataCite metadata with emails

if production == True:
url = "https://data.caltech.edu/api/records/"
if authors:
url = "https://authors.library.caltech.edu/api/records/"
else:
url = "https://data.caltech.edu/api/records/"
verify = True
else:
url = "https://data.caltechlibrary.dev/api/records/"
if authors:
url = "https://authors.caltechlibrary.dev/api/records/"
else:
url = "https://data.caltechlibrary.dev/api/records/"
verify = True

headers = {
"accept": "application/vnd.datacite.datacite+json",
}
if authors:
headers = {
"accept": "application/json",
}
validate = False
else:
headers = {
"accept": "application/vnd.datacite.datacite+json",
}

if token:
headers["Authorization"] = "Bearer %s" % token

response = requests.get(url + idv, headers=headers, verify=verify)
print(response.headers)
if response.status_code != 200:
raise Exception(response.text)
else:
Expand Down Expand Up @@ -59,6 +76,7 @@ def get_metadata(
help="The CaltechDATA ID for each record of interest",
)
parser.add_argument("-test", dest="production", action="store_false")
parser.add_argument("-authors", dest="authors", action="store_true")
parser.add_argument("-xml", dest="save_xml", action="store_true")
parser.add_argument(
"-skip_validate",
Expand All @@ -72,14 +90,17 @@ def get_metadata(

production = args.production
schema = args.schema
authors = args.authors
skip_validate = args.skip_validate
if skip_validate:
validate = False
else:
validate = True

for idv in args.ids:
metadata = get_metadata(idv, production, validate, schema)
metadata = get_metadata(
idv, production, validate, schema=schema, authors=authors
)
outfile = open(str(idv) + ".json", "w")
outfile.write(json.dumps(metadata, indent=4))
outfile.close()
Expand Down
Loading

0 comments on commit ed93fa8

Please sign in to comment.