inveniosoftware / cookiecutter-invenio-rdm

Cookiecutter template for a new InvenioRDM instance.
MIT License
4 stars 33 forks source link

fixtures: update ROR affiliations data as of `2024-05-02` #281

Closed Samk13 closed 2 months ago

Samk13 commented 5 months ago

:heart: Thank you for your contribution!

Description

Here is the code used to convert the data for easier review:

import json
import yaml

def convert_json_to_yaml(json_filepath, yaml_filepath):
    with open(json_filepath, 'r', encoding='utf-8') as json_file, open(yaml_filepath, 'w', encoding='utf-8') as yaml_file:
        data = json.load(json_file)

        yaml_data = []
        for item in data:
            identifier_entry = {
                'identifier': item['id'].split('/')[-1],
                'scheme': 'ror'
            }

            # Prepare the title structure with translations if available
            title = {'en': item['name']}  # default to English title
            for label in item.get('labels', []):
                if label.get('iso639') and label.get('label'):
                    title[label['iso639']] = label['label']

            # Prepare the basic YAML entry structure
            yaml_entry = {
                'id': item['id'].split('/')[-1],
                'name': item['name'],
                'title': title,
                'identifiers': [identifier_entry]
            }

            # Check if acronyms is not empty and add if it's not
            if item['acronyms'] and item['acronyms'][0] != "":
                yaml_entry['acronym'] = item['acronyms'][0]

            yaml_data.append(yaml_entry)

        yaml.safe_dump(yaml_data, yaml_file, allow_unicode=False, default_flow_style=False)

json_input = "v1.46-2024-05-02-ror-data.json"
yaml_output = "affiliations_ror.yaml"

convert_json_to_yaml(json_input, yaml_output)

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.
Samk13 commented 2 months ago

Closing in favor of https://github.com/inveniosoftware/cookiecutter-invenio-rdm/pull/282