Skip to content

Instantly share code, notes, and snippets.

@vmx
Created May 1, 2021 14:44
Show Gist options
  • Save vmx/7481f30d7beac6636a4b432f543f47f5 to your computer and use it in GitHub Desktop.
Save vmx/7481f30d7beac6636a4b432f543f47f5 to your computer and use it in GitHub Desktop.
Upload links on Seafile for conference talks submitted to pretalx
#!/bin/sh
#set -o xtrace
# SPDX-FileCopyrightText: Volker Mische <[email protected]>
# SPDX-License-Identifier: MIT
# Creates a directory with the given name (sub-directories are not supported)
# in the root of the repo returns its name together with the upload link as
# JSON, where the directory name is the key and the upload link is the value.
# You can get your auth token via
# curl -X POST --data "username=<your-username>&password=<your-password>" '<you-server>/api2/auth-token/'
if [ "${#}" -lt 4 ]; then
echo "Usage: $(basename "${0}") <base-url> <auth-token> <repo-id> <directory-name>"
echo ""
echo "Example: $(basename "${0}") https://example.org fe91e764226cc534811f0ba32c62a6ac41ad0d7b 280b593a-f868-0594-d97a-23d88822a35f directory_to_create"
exit 1
fi
base_url=${1}
token=${2}
repo_id=${3}
dir_name=${4}
api_v20="${base_url}/api2"
api_v21="${base_url}/api/v2.1"
mkdir_ret=$(curl --silent -X POST --header "Authorization: Token ${token}" "${api_v20}/repos/${repo_id}/dir/?p=/${dir_name}" --data 'operation=mkdir')
if [ "${mkdir_ret}" != '"success"' ]; then
echo "Error: cannot create directory '${dir_name}'."
exit 2
fi
# Output the directory name to stderr (so that you can still pipe the expected
# output into a fil) as progress indicator
echo "Creating ${dir_name} on Seafile…" >&2
upload_link_ret=$(curl --silent -X POST --header "Authorization: Token ${token}" "${api_v21}/upload-links/" --data "path=/${dir_name}/&repo_id=${repo_id}"|jq --compact-output '{(.obj_name): .link}')
echo "${upload_link_ret}"
#!/usr/bin/env python3
import argparse
import json
import sys
import urllib.request
parser = argparse.ArgumentParser(
description='Get all the data from a pretalx endpoint.')
parser.add_argument('token', help='token for the API')
parser.add_argument('url', help='pretalx API URL')
args = parser.parse_args()
url = args.url
token = args.token
# `combined` is the final output, it's the combined result of all requests
combined = {
'count': 0,
'next': None,
'previous': None,
'results': []
}
# Keep going as long as there are more pages to fetch
while (url):
# Print the current URL that will be requested to stderr to see the
# progress. This way you can easily pipe the actual result which is
# printed to the stdout into a file.
print(f'{url}', file=sys.stderr)
req = urllib.request.Request(url, headers={
'Authorization': f'Token {token}'
})
with urllib.request.urlopen(req) as resp:
# Parse the response so that we combine it easily
data = json.load(resp)
# Add the current result to the combined data
combined['results'].extend(data['results'])
# The `count` is always the total number of items, so we can safely
# override it
combined['count'] = data['count']
# Prepare for the next loop iteration. If there is no more data `next`
# will be `None` and the loop will abort
url = data['next']
print(json.dumps(combined))
#!/bin/sh
#set -o xtrace
# SPDX-FileCopyrightText: Volker Mische <[email protected]>
# SPDX-License-Identifier: MIT
# Creates directories on Seafile to upload talks which were submitted to
# pretalx. The output is a CSV file containing the pretalx code of the talk,
# its title, the submission type, the submitters name, their email address and
# the upload link.
#
# Please note that this script it tailered for the FOSSGIS 2021, it filters
# out certain submission types. Though this should be the only specific thing
# so it should be re-usable for other conferences that use pretalx and Seafile.
#
# As all options are mandatory, please use the specific order, I didn't want
# to complicate the script unnecessarily.
#
# You need to have the following utilities installed:
# jq, python3, xargs
#
# This script creates a directory called `out` which contains all the files
# that are created when running this script. The final output is called
# `email_data.csv`
# You can get your auth token via
# curl -X POST --data "username=<your-username>&password=<your-password>" '<you-server>/api2/auth-token/'
if [ "${#}" -lt 5 ]; then
echo "Usage: $(basename "${0}") <pretalx-api-url> <pretalx-api-token> <seafile-base-url> <seafile-auth-token> <seafile-repo-id>"
echo ""
echo "Example: $(basename "${0}") https://pretalx.com/api/events/your-event cc78456d498548331ea9b744f262fa68d23d27e8 https://example.org fe91e764226cc534811f0ba32c62a6ac41ad0d7b 280b593a-f868-0594-d97a-23d88822a35f"
exit 1
fi
pretalx_api_url=${1}
pretalx_api_token=${2}
seafile_base_url=${3}
seafile_api_token=${4}
seafile_repo_id=${5}
mkdir -p out
cd out || exit 2
# The pretalx part
echo "Getting data from pretalx…"
# We only care about the confirmed talks
python3 ../pretalx-get-all.py "${pretalx_api_token}" "${pretalx_api_url}/submissions/?state=confirmed" > confirmed.json
# Create a list of talk IDs. This file is used as the source to create the
# direcotries on Seafile
jq -r '.results[] | select((.submission_type[] | contains("Workshop")) or (.submission_type[] == "Anwendertreffen / BoF") | not) | .code' < confirmed.json > dirs.txt
# Exclude certain types of submissions. This should be the only FOSSGIS 2021
# specific step.
# It de-duplicates the data, so that it is one entry per speaker, as we want
# to send the email about the upload link to all speakers of a talk
jq '[.results[] | select((.submission_type[] | contains("Workshop")) or (.submission_type[] == "Anwendertreffen / BoF") | not) | { code: .code, speaker: .speakers[].code, title: .title, submission_type: .submission_type[]}]' < confirmed.json > talks.json
# Get all the speakers
python3 ../pretalx-get-all.py "${pretalx_api_token}" "${pretalx_api_url}/speakers/" > speakers.json
# Transform the file to one where the speaker code (identifier) is the key and the value their name and email address
jq '.results[] | {(.code): {name, email}}' < speakers.json|jq -s 'add' > speakers_name_email.json
# The Seafile part
echo "Creating directories on seafile…"
# Create the directories on Seafile and return the upload links to them
xargs -n1 -I{} ../createdirs.sh "${seafile_base_url}" "${seafile_api_token}" "${seafile_repo_id}" {} < dirs.txt > upload_links.ndjson
jq -s 'add' < upload_links.ndjson > upload_links.json
# Final output part
# Combine all the data we've gathered and produce a CSV file that can be used
# as input to send emails
python3 ../combine_talks_speakers_upload_links.py|jq -r '(.[0] | keys_unsorted) as $keys | $keys, map([.[ $keys[] ]])[] | @csv' > email_data.csv
echo "Final output can be found at \`out/email_data.csv\`."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment