Skip to content

Instantly share code, notes, and snippets.

@brianteeman
Last active June 19, 2025 15:38
Show Gist options
  • Save brianteeman/1fa17e9ad95fae4fee23cafa414c142a to your computer and use it in GitHub Desktop.
Save brianteeman/1fa17e9ad95fae4fee23cafa414c142a to your computer and use it in GitHub Desktop.
Import csv to Joomla
#!/bin/bash
# --- CONFIGURATION ---
JOOMLA_API="https://<INSERT_DOMAIN>/api/index.php/v1/content/articles"
JOOMLA_TOKEN="<INSERT_API_TOKEN>"
CATID=24 # Change to your Joomla category ID
if [ ! -f all-contributors.csv ]; then
echo "all-contributors.csv not found in current directory."
exit 1
fi
# Read CSV and skip header
tail -n +2 all-contributors.csv | while IFS=, read -r login name avatar_url html_url contributions; do
# Remove quotes if present
login=$(echo "$login" | sed 's/^"\(.*\)"$/\1/')
name=$(echo "$name" | sed 's/^"\(.*\)"$/\1/')
avatar_url=$(echo "$avatar_url" | sed 's/^"\(.*\)"$/\1/')
html_url=$(echo "$html_url" | sed 's/^"\(.*\)"$/\1/')
contributions=$(echo "$contributions" | sed 's/^"\(.*\)"$/\1/')
# Use login as title if name is empty
if [ -z "$name" ] || [ "$name" = "null" ]; then
title="$login"
else
title="$name"
fi
# Create an alias from login (lowercase, dashes)
alias=$(echo "$login" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
avatar="${avatar_url}&s=100"
url="$html_url"
# Compose article JSON (basic, no jq)
json=$(cat <<EOF
{
"title": "$title",
"alias": "$alias",
"catid": "$CATID",
"introtext": "",
"state": 1,
"access": 1,
"language": "*",
"created_by_alias": "GitHub Importer",
"images": {
"image_intro": "$avatar",
"image_intro_alt": "$title",
"image_fulltext": "$avatar",
"image_fulltext_alt": "$title"
},
"githuburl": "$url",
"githubcontributions": "$contributions"
}
EOF
)
# POST to Joomla API
curl -s -X POST "$JOOMLA_API" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $JOOMLA_TOKEN" \
-d "$json"
done
echo "Done! Articles created for all contributors."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment