Skip to content

Instantly share code, notes, and snippets.

View slint's full-sized avatar

Alex Ioannidis slint

View GitHub Profile
from sickle import Sickle
harvester = Sickle('https://zenodo.org/oai2d')
records_iterator = harvester.ListRecords(
metadataPrefix='oai_datacite', # or 'oai_dc'
set='user-kios-coe')
for record in records_iterator:
print(record.header.identifier)
# oai:zenodo.org:1039010
# oai:zenodo.org:1037132
  1. Create an access token at "https://zenodo.org/account/settings/applications/tokens/new/" with the "deposit:write" and "deposit:actions" scopes, and keep it somewhere safe (we'll refer to this token as ZENODO_TOKEN)
  2. Create your deposit via the web interface at "https://zenodo.org/deposit/new", fill in the minimum metadata (title, authors, description, access rights and license) and click "Save".
  3. On your browser's URL, you will now see the deposit ID in the form "https://zenodo/deposit/".
  4. Next step is to get the file upload URL. Via curl (or your HTTP client of preference) you can do:
$ # Store the Zenodo token in an envionrment variable
$ read -s ZENODO_TOKEN
$ curl "https://zenodo.org/api/deposit/depositions/222761?access_token=${ZENODO_TOKEN}"
{ ...  
# Fetch events from DataCite
curl -G https://api.datacite.org/events \
-d source-id=crossref \
-d relation-type-id=references \
-d prefix=10.5281 > datacite-0.json
# Get next page from ".links.next" link
curl "$(jq -r .links.next datacite-0.json)" > datacite-1.json
# Fetch events from Crossref
curl -G https://api.eventdata.crossref.org/v1/events \
yadayada
alabaster==0.7.10
apipkg==1.4
appnope==0.1.0
attrdict==2.0.0
attrs==17.4.0
Babel==2.5.3
certifi==2018.1.18
chardet==3.0.4
check-manifest==0.36
@slint
slint / Vagrantfile
Last active March 13, 2019 10:20
Invenio Bootcamp Vagrant setup
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
# Enable GUI
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
# Create a synced folder
@slint
slint / record-v1.0.0.json
Created March 21, 2019 15:03
nested record example
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://zenodo.org/schemas/records/record-v1.0.0.json",
"properties": {
"formats": {
"type": "array",
"items": {
"type": "object",
"properties": {
"width": {
@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"
{
<?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
########
# in invenio_app/csrf.py
class CSRF(object):
def init_app(self, app):
@app.before_request
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>',