Skip to content

Instantly share code, notes, and snippets.

View slint's full-sized avatar

Alex Ioannidis slint

View GitHub Profile
@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}"

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 / 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": {
"""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 / 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" \
@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",
...
import requests
res = requests.post(
'https://zenodo.org/oauth/token',
# This is a form submission, i.e. Content-Type: application/x-www-form-urlencoded
data={
'grant_type': 'authorization_code',
# the "code" parameter passed to the callback URL
'code': '<AUTHORIZATION_CODE>',
'client_id': '<CLIENT_ID>',
'client_secret': '<CLIENT_SECRET>',
########
# in invenio_app/csrf.py
class CSRF(object):
def init_app(self, app):
@app.before_request
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:adms="http://www.w3.org/ns/adms#" xmlns:cnt="http://www.w3.org/2011/content#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcat="http://www.w3.org/ns/dcat#" xmlns:dct="http://purl.org/dc/terms/" xmlns:dctype="http://purl.org/dc/dcmitype/" xmlns:duv="http://www.w3.org/ns/duv#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:frapo="http://purl.org/cerif/frapo/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:gsp="http://www.opengis.net/ont/geosparql#" xmlns:locn="http://www.w3.org/ns/locn#" xmlns:org="http://www.w3.org/ns/org#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:prov="http://www.w3.org/ns/prov#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:vcard="http://www.w3.org/2006/vcard/ns#" xmlns:wdrs="http://www.w3.org/2007/05/powder-s#">
<rdf:Description rdf:about="https://doi.org/10.528
@slint
slint / zenodo-restricted-curl.sh
Created April 15, 2019 08:54
Zenodo restricted access REST API usage
# Let's assume you have received via email the secret link:
# https://zenodo.org/record/123456?token=<LONG-TOKEN-HERE>
# Make a curl request, but store the cookies in a file:
$ curl --cookie-jar zenodo-cookies.txt "https://zenodo.org/record/123456?token=<LONG-TOKEN-HERE>"
...HTML output...
# Use the cookie file to make subsequent requests to the api:
$ curl --cookie zenodo-cookies.txt "https://zenodo.org/api/records/123456"
{