-
Notifications
You must be signed in to change notification settings - Fork 1
feat(api): add account creation automation shell script #10
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # === DESCRIPTION ================== | ||||||||||||||||||||||||||||||||||||
| # This script creates accounts for a list of participants in a TSV file. | ||||||||||||||||||||||||||||||||||||
| # The TSV file should have the following columns: | ||||||||||||||||||||||||||||||||||||
| # Occupation/Specialty Email Prolific ID. | ||||||||||||||||||||||||||||||||||||
| # The script will randomly select a specified number of participants and create accounts for them. | ||||||||||||||||||||||||||||||||||||
| # The script uses the Prolific API to create accounts. | ||||||||||||||||||||||||||||||||||||
| # The script requires the following environment variables to be set: | ||||||||||||||||||||||||||||||||||||
| # - API_URL: The URL of the admin API for creating accounts. | ||||||||||||||||||||||||||||||||||||
| # - API_KEY: The API key for admin API for creating accounts. | ||||||||||||||||||||||||||||||||||||
| # The script will create accounts for the specified number of participants and print the number of accounts created. | ||||||||||||||||||||||||||||||||||||
| # The script will also print the number of accounts created. | ||||||||||||||||||||||||||||||||||||
| # ================================== | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # === CONFIGURATION === | ||||||||||||||||||||||||||||||||||||
| API_URL="api_url_here" | ||||||||||||||||||||||||||||||||||||
| API_KEY="api_key_here | ||||||||||||||||||||||||||||||||||||
| INPUT_FILE="participants.tsv" | ||||||||||||||||||||||||||||||||||||
| NUM_SAMPLES=100 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # === sanity check === | ||||||||||||||||||||||||||||||||||||
| if [ ! -f "$INPUT_FILE" ]; then | ||||||||||||||||||||||||||||||||||||
| echo "Error: '$INPUT_FILE' not found. Please save your list as a TSV with columns:" \ | ||||||||||||||||||||||||||||||||||||
| "Occupation/Specialty<TAB>Email<TAB>Prolific ID." >&2 | ||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # === helper to produce randomized lines of "email|id" with valid emails only === | ||||||||||||||||||||||||||||||||||||
| random_stream() { | ||||||||||||||||||||||||||||||||||||
| awk -F'\t' ' | ||||||||||||||||||||||||||||||||||||
| BEGIN { srand() } | ||||||||||||||||||||||||||||||||||||
| NR>1 && NF>=3 { | ||||||||||||||||||||||||||||||||||||
| email = $2 | ||||||||||||||||||||||||||||||||||||
| # trim leading/trailing whitespace | ||||||||||||||||||||||||||||||||||||
| gsub(/^[[:space:]]+|[[:space:]]+$/, "", email) | ||||||||||||||||||||||||||||||||||||
| # only keep if looks like [email protected] (no spaces) | ||||||||||||||||||||||||||||||||||||
| if (email ~ /^[^[:space:]]+@[^[:space:]]+\.[^[:space:]]+$/) { | ||||||||||||||||||||||||||||||||||||
| printf "%f\t%s|%s\n", rand(), email, $3 | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| ' "$INPUT_FILE" \ | ||||||||||||||||||||||||||||||||||||
| | sort -n | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # === build the JSON array === | ||||||||||||||||||||||||||||||||||||
| users_json="[" | ||||||||||||||||||||||||||||||||||||
| count=0 | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| while IFS=$'\t' read -r _ pair; do | ||||||||||||||||||||||||||||||||||||
| IFS='|' read -r email id <<< "$pair" | ||||||||||||||||||||||||||||||||||||
| users_json+=$( | ||||||||||||||||||||||||||||||||||||
| printf '{"name":"Prolific ID: %s","email":"%s","position":"Physician Assistant (PA)","employer":"n/a","area_of_clinical_ex":"n/a"},' \ | ||||||||||||||||||||||||||||||||||||
| "$id" "$email" | ||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||
| count=$((count+1)) | ||||||||||||||||||||||||||||||||||||
| [ "$count" -ge "$NUM_SAMPLES" ] && break | ||||||||||||||||||||||||||||||||||||
| done < <(random_stream) | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+51
to
+59
|
||||||||||||||||||||||||||||||||||||
| while IFS=$'\t' read -r _ pair; do | |
| IFS='|' read -r email id <<< "$pair" | |
| users_json+=$( | |
| printf '{"name":"Prolific ID: %s","email":"%s","position":"Physician Assistant (PA)","employer":"n/a","area_of_clinical_ex":"n/a"},' \ | |
| "$id" "$email" | |
| ) | |
| count=$((count+1)) | |
| [ "$count" -ge "$NUM_SAMPLES" ] && break | |
| done < <(random_stream) | |
| while IFS=$'\t' read -r occupation email id; do | |
| users_json+=$( | |
| printf '{"name":"Prolific ID: %s","email":"%s","position":"%s","employer":"n/a","area_of_clinical_ex":"n/a"},' \ | |
| "$id" "$email" "$occupation" | |
| ) | |
| count=$((count+1)) | |
| [ "$count" -ge "$NUM_SAMPLES" ] && break | |
| done < <(random_stream | awk -F'|' '{print $1"\t"$2"\t"$3}') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding placeholder values can cause confusion. Instead, read from the environment and validate, e.g.:
: "${API_URL:?Please set API_URL}"and remove the default assignment.