Skip to content

Instantly share code, notes, and snippets.

View slint's full-sized avatar

Alex Ioannidis slint

View GitHub Profile
@slint
slint / flows.txt
Last active February 4, 2020 13:52
Zenodo REST API flows
# Create the record
POST /api/deposit/depositions
{}
201
{
"id": 123,
"links": {
"bucket": "/api/files/<bucket-id>",
"publish": "/api/deposit/depositions/123/actions/publish",
...
@slint
slint / zenodo-versioning.sh
Created February 11, 2020 12:15
Zenodo REST API example in cURL
#!/bin/bash
BASE_URL="https://sandbox.zenodo.org"
API_TOKEN="<your-token>"
# 1. Create the first version
curl -i -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
"$BASE_URL/api/deposit/depositions" \
"""Demo communities and members creation.
Note: run ``pip install faker`` to use
"""
import uuid
from faker import Faker
from flask import current_app
from flask_security.utils import hash_password
from invenio_db import db
@slint
slint / community_records_addition.json
Last active June 24, 2021 17:27
Zenodo webhook event payloads
{
"timestamp": "2019-10-23T18:19:36.995076+00:00",
"id": "7203d723-7bdd-40e9-bea0-453b17397ad9",
"event_type": "community.records.addition",
"context": {
"community": "biosyslit",
"user": 1161
},
"payload": {
"community": {

Resource access tokens (RATs)

Summary

Allow users to generate via their OAuth2 Personal Access Tokens short-lived signed JWTs that enable granular access to a specific resource. This is useful for:

  • Ad-hoc generation of "secret" links to private resources, like e.g. closed-access files
  • Integration with 3rd-party systems that use your platform to store records, and don't want to proxy all the protected resources via their system
@slint
slint / zenodo-community-stats.sh
Last active December 27, 2023 13:29
Fetch Zenodo stats for communities and queries
#!/bin/bash
# To use this script you need to have "curl" and "jq" installed.
COMMUNITY_ID="community_id"
OUTPUT_CSV="${COMMUNITY_ID}_community_stats.csv"
# Create CSV file header
echo "URL,DOI,Title,PublicationDate,Views,Downloads" > "${OUTPUT_CSV}"
@slint
slint / names.sql
Last active February 21, 2025 15:24
Instructions to import the CSV version of the ORCiD public data produced by https://github.com/slint/orcid-data-toolkit
-- Create a new table with the new schema (excluding constraints and indexes)
CREATE TABLE name_metadata_new
(LIKE name_metadata EXCLUDING CONSTRAINTS EXCLUDING INDEXES);
-- Time: 0.337s
-- Copy the CSV data into the new table, running the following in a shell:
-- export DB_URI="CHANGE_ME"
-- gzip -dc orcid-names-2024.csv.gz | pv --line-mode --average-rate --timer | psql $DB_URI -c 'COPY name_metadata_new (created, updated, id, json, version_id, pid) FROM STDIN (FORMAT CSV);'
-- Time: 210.000s (3 minutes 30 seconds)