Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload via script #67

Open
baiddd opened this issue Mar 28, 2022 · 1 comment
Open

upload via script #67

baiddd opened this issue Mar 28, 2022 · 1 comment

Comments

@baiddd
Copy link
Contributor

baiddd commented Mar 28, 2022

Hi, @oeway
I try to upload the localization files (.csv) via python script, seems it doesn't work with tags shareloc and shareloc: dataset, I even generated rdf.yaml file but there is no card appeared on shareloc with sandbox mod, could you took into it when you are available?
Thanks,

@oeway
Copy link
Collaborator

oeway commented Mar 28, 2022

Hi, it won't appear automatically, in order to be displayed, you need to set the metadata correctly, this is how we construct the metadata for the depoist:

ShareLoc.XYZ/src/utils.js

Lines 261 to 364 in b3d7a8d

export function rdfToMetadata(rdf, baseUrl, docstring) {
if (!spdxLicenseList[rdf.license])
throw new Error(
"Invalid license, the license identifier must be one from the SPDX license list (https://spdx.org/licenses/)"
);
if (!rdf.type) {
throw new Error("`type` key is not defined in the RDF.");
}
rdf.covers = rdf.covers || [];
const covers = rdf.covers.map(c =>
c.startsWith("http") ? c : new URL(c, baseUrl).href
);
const related_identifiers = [];
for (let c of covers) {
if (c.includes("access_token="))
throw new Error("Cover URL should not contain access token: " + c);
related_identifiers.push({
relation: "hasPart", // is part of this upload
identifier: c,
resource_type: "image-figure",
scheme: "url"
});
}
rdf.links = rdf.links || [];
for (let link of rdf.links) {
if (link.includes("access_token="))
throw new Error("Link should not contain access token: " + link);
related_identifiers.push({
identifier: "https://shareloc.xyz/#/r/" + encodeURIComponent(link),
relation: "references", // is referenced by this upload
resource_type: "other",
scheme: "url"
});
}
if (rdf.config._rdf_file)
// rdf.yaml
related_identifiers.push({
identifier: rdf.config._rdf_file.startsWith("http")
? rdf.config._rdf_file
: new URL(rdf.config._rdf_file, baseUrl).href,
relation: "isCompiledBy", // compiled/created this upload
resource_type: "other",
scheme: "url"
});
else throw new Error("`_rdf_file` key is not found in the RDF config");
// if (rdf.attachments && rdf.attachments.samples) {
// const samples = rdf.attachments.samples.map(d =>
// d.download_url ? d.download_url : new URL(d.name, baseUrl).href
// );
// samples.forEach(dataset => {
// related_identifiers.push({
// relation: "hasPart", // is part of this upload
// identifier: dataset,
// resource_type: "dataset",
// scheme: "url"
// });
// });
// }
if (rdf.documentation) {
if (rdf.documentation.includes("access_token="))
throw new Error("Documentation URL should not contain access token");
related_identifiers.push({
identifier: rdf.documentation.startsWith("http")
? rdf.documentation
: new URL(rdf.documentation, baseUrl).href,
relation: "isDocumentedBy", // is referenced by this upload
resource_type: "publication-technicalnote",
scheme: "url"
});
}
rdf.authors = rdf.authors || [];
const creators = rdf.authors.map(author => {
if (typeof author === "string")
return { name: author.split(";")[0], affiliation: "" };
else
return {
name: author.name.split(";")[0],
affiliation: author.affiliation,
orcid: author.orcid
};
});
const description =
`<a href="https://shareloc.xyz/#/r/zenodo:${encodeURIComponent(
rdf.config._deposit.id
)}"><span class="label label-success">Open in Shareloc.XYZ</span></a><br>` +
((docstring && `<p>${docstring}</p>`) || "");
const keywords = ["shareloc.xyz", "shareloc.xyz:" + rdf.type];
const metadata = {
title: rdf.name,
description,
access_right: "open",
license: rdf.license,
upload_type: "other",
creators: creators,
publication_date: new Date().toISOString().split("T")[0],
keywords: keywords.concat(rdf.tags),
notes: rdf.description + additionalNote,
related_identifiers,
communities: []
};
return metadata;
}

In addition, you also need to add the deposit to the shareloc-xyz community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants