|
| 1 | +# ======================= |
| 2 | +# CONFIGURATION PARAMETERS |
| 3 | +# ======================= |
| 4 | +doi = "" # Full DOI, e.g., "doi:10.34810/data123456" |
| 5 | +token = "" # API token from https://dataverse.csuc.cat/dataverseuser.xhtml?selectTab=apiTokenTab |
| 6 | +driver = None # Use: webdriver.Chrome(), webdriver.Firefox(), or None |
| 7 | +opcions = [ |
| 8 | + "Universitat Rovira i Virgili", |
| 9 | + "Universitat Pompeu Fabra", |
| 10 | + "Universitat Oberta de Catalunya", |
| 11 | + "Vall d’Hebron Institut de Recerca", |
| 12 | + "Centre for Research on Ecology and Forestry Applications", |
| 13 | + "Universitat Ramon Llull", |
| 14 | + "Consorci Institut D'Investigacions Biomèdiques August Pi i Sunyer", |
| 15 | + "Centre de Recerca en Agrigenòmica", |
| 16 | + "Institut Català de Nanociència i Nanotecnologia", |
| 17 | + "Institut de Recerca Sant Joan de Déu", |
| 18 | + "Universitat Autònoma de Barcelona", |
| 19 | + "Universitat Politècnica de Catalunya", |
| 20 | + "Consorci de Serveis Universitaris de Catalunya", |
| 21 | + "Institut de Física d'Altes Energies", |
| 22 | + "Universitat Internacional de Catalunya", |
| 23 | + "Centre de Recerca Matemàtica", |
| 24 | + "Institut d'Investigació Biomèdica de Bellvitge", |
| 25 | + "Universitat de Lleida", |
| 26 | + "Universitat de Girona", |
| 27 | + "i2CAT", |
| 28 | + "Institut de Recerca i Tecnologia Agroalimentàries", |
| 29 | + "Fundación Josep Carreras Contra la Leucemia", |
| 30 | + "Centre for Demographic Studies", |
| 31 | + "Centre Tecnològic Forestal de Catalunya", |
| 32 | + "Universitat de Vic - Universitat Central de Catalunya", |
| 33 | + "IrsiCaixa", |
| 34 | + "Institute for Bioengineering of Catalonia", |
| 35 | + "Biomedical Research Institute of Lleida", |
| 36 | + "Institut Barcelona d'Estudis Internacionals", |
| 37 | + "Barcelona University", |
| 38 | + "Catalan Institute for Water Research", |
| 39 | + "Institute of Research and Innovation Parc Taulí", |
| 40 | + "Institut Català de Paleoecologia Humana i Evolució Social", |
| 41 | + "Universitat de les Illes Balears", |
| 42 | + "Institute of Photonic Sciences", |
| 43 | + "Institute for Research in Biomedicine", |
| 44 | + "Agrotecnio - Centre for Food and Agriculture Research", |
| 45 | + "Institut d'Investigació Biomèdica de Girona", |
| 46 | + "Institut Català d'Arqueologia Clàssica", |
| 47 | + "Barcelona Institute for Global Health" |
| 48 | +] |
| 49 | + |
| 50 | + |
| 51 | +# ======================= |
| 52 | +# IMPORTS & INSTALLATION |
| 53 | +# ======================= |
| 54 | +import os |
| 55 | +import sys |
| 56 | +import subprocess |
| 57 | +from datetime import date |
| 58 | +from pyDataverse.api import NativeApi |
| 59 | +from selenium import webdriver |
| 60 | +from selenium.webdriver.common.by import By |
| 61 | +from collections import Counter |
| 62 | +from IPython.display import HTML, display |
| 63 | + |
| 64 | +# Install necessary packages if running interactively (optional) |
| 65 | +def install_packages(): |
| 66 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "pip"]) |
| 67 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "pyDataverse"]) |
| 68 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "selenium"]) |
| 69 | + subprocess.check_call([sys.executable, "-m", "pip", "install", "--upgrade", "tensorflow-probability"]) |
| 70 | + |
| 71 | +# ======================= |
| 72 | +# MAIN FUNCTION |
| 73 | +# ======================= |
| 74 | +def Meta(doi, token, driver, opcions): |
| 75 | + today = date.today() |
| 76 | + print("Data:", today) |
| 77 | + |
| 78 | + base_url = 'https://dataverse.csuc.cat/' |
| 79 | + api = NativeApi(base_url, token) |
| 80 | + Metadata = api.get_dataset(doi) |
| 81 | + |
| 82 | + fields_metadata = Metadata.json()["data"]["latestVersion"]["metadataBlocks"]["citation"]["fields"] |
| 83 | + metadata_repositori = [field["typeName"] for field in fields_metadata] |
| 84 | + |
| 85 | + Metadata_min_req = ['title', 'datasetContact', 'dsDescription', 'keyword', 'subject', 'kindOfData', 'author'] |
| 86 | + intersect_metadata = list(set(metadata_repositori) & set(Metadata_min_req)) |
| 87 | + same_metadata = len(list(set(Metadata_min_req) ^ set(intersect_metadata))) |
| 88 | + |
| 89 | + print("\nConté les metadades mínimes obligatòries?") |
| 90 | + if same_metadata != 0: |
| 91 | + print("NO", list(set(Metadata_min_req) ^ set(intersect_metadata))) |
| 92 | + else: |
| 93 | + print("SÍ") |
| 94 | + |
| 95 | + # Title |
| 96 | + index_title = metadata_repositori.index('title') |
| 97 | + titol = fields_metadata[index_title]["value"] |
| 98 | + print("\nTítol dataset:\n{}\n".format(titol)) |
| 99 | + |
| 100 | + titol_1 = titol.split(":") |
| 101 | + |
| 102 | + # Related publication |
| 103 | + print("En el cas que el dataset tingui una publicació relacionada, inclou la citació?") |
| 104 | + if 'publication' in metadata_repositori: |
| 105 | + print("SÍ") |
| 106 | + index_publication = metadata_repositori.index('publication') |
| 107 | + Rel_pub = [pub["publicationCitation"]["value"] for pub in fields_metadata[index_publication]["value"]] |
| 108 | + for citation in Rel_pub: |
| 109 | + print(citation) |
| 110 | + |
| 111 | + if "Replication Data for" in titol_1[0] and len(titol_1) > 1: |
| 112 | + only_title = titol[21:] |
| 113 | + print("\nEl títol inclou: Replication data for") |
| 114 | + for i in Rel_pub[0].split("."): |
| 115 | + if only_title.casefold() == i.strip().casefold(): |
| 116 | + print("Els títols coincideixen") |
| 117 | + else: |
| 118 | + print("\nNo és rèplica de l'article") |
| 119 | + else: |
| 120 | + print("\nNo té publicacions relacionades") |
| 121 | + |
| 122 | + # Author info |
| 123 | + index_author = metadata_repositori.index('author') |
| 124 | + author_id = [] |
| 125 | + afiliacion = [] |
| 126 | + institucion = [] |
| 127 | + |
| 128 | + for author in fields_metadata[index_author]["value"]: |
| 129 | + aff = author.get("authorAffiliation", {}) |
| 130 | + aff_val = aff.get("expandedvalue", {}).get("termName") or aff.get("value") |
| 131 | + if aff_val: |
| 132 | + afiliacion.append(aff_val) |
| 133 | + |
| 134 | + if "authorIdentifier" in author: |
| 135 | + author_id.append("SÍ") |
| 136 | + |
| 137 | + for aff in afiliacion: |
| 138 | + matched = any(inst in aff for inst in opcions) |
| 139 | + institucion.append("SÍ" if matched else "NO") |
| 140 | + |
| 141 | + print("\nAlmenys un/a dels/les autors/es pertany a la institució on es diposita:", "SÍ" if "SÍ" in institucion else "NO") |
| 142 | + print("Almenys un/a dels/les autors/es informa del seu ORCID?") |
| 143 | + print("ORCID: ", "SÍ" if "SÍ" in author_id else "NO") |
| 144 | + |
| 145 | + # Description |
| 146 | + index_descripcion = metadata_repositori.index('dsDescription') |
| 147 | + descripcion = fields_metadata[index_descripcion]["value"][0]['dsDescriptionValue']["value"] |
| 148 | + print("\nDescripció:\n", descripcion) |
| 149 | + |
| 150 | + # File formats |
| 151 | + print("\nFormat de fitxers") |
| 152 | + total_files = len(Metadata.json()['data']['latestVersion']['files']) |
| 153 | + files = [file['dataFile']['filename'] for file in Metadata.json()['data']['latestVersion']['files']] |
| 154 | + extensions = [os.path.splitext(f)[1] for f in files] |
| 155 | + print(Counter(extensions)) |
| 156 | + |
| 157 | + lowercase_files = [f.lower() for f in files] |
| 158 | + if "readme.txt" in lowercase_files: |
| 159 | + print("Sí que conté el fitxer readme.txt") |
| 160 | + |
| 161 | + # License |
| 162 | + print("\nLlicència:") |
| 163 | + license_info = Metadata.json()["data"]['latestVersion'].get("license", {}).get("name") \ |
| 164 | + or Metadata.json()["data"]['latestVersion'].get('termsOfUse') |
| 165 | + print(license_info) |
| 166 | + |
| 167 | + # F-UJI |
| 168 | + if driver is None: |
| 169 | + print("\nAvalueu el dataset manualment a F-UJI: https://www.f-uji.net/") |
| 170 | + else: |
| 171 | + driver.get("https://www.f-uji.net/") |
| 172 | + driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div/p/a').click() |
| 173 | + driver.find_element(By.XPATH, '//*[@id="pid"]').send_keys(doi) |
| 174 | + driver.find_element(By.XPATH, '//*[@id="assessment_form"]/div/form/div[4]/button').click() |
| 175 | + |
| 176 | + |
| 177 | +# ======================= |
| 178 | +# EXECUTE SCRIPT |
| 179 | +# ======================= |
| 180 | +if __name__ == "__main__": |
| 181 | + Meta(doi, token, driver, opcions) |
0 commit comments