Created
November 5, 2024 18:23
-
-
Save cmilfont/4bf6904336b0c726f1e40fd1c1d378ca to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
# URL base | |
BASE_URL="https://www.credly.com/api/v1/directory?organization_id=63074953-290b-4dce-86ce-ea04b4187219&sort=alphabetical&filter%5Blocation_name%5D=Brazil&page=" | |
# Tamanho da página | |
PAGE_SIZE=8 | |
# Arquivo CSV de saída | |
OUTPUT_FILE="github-certs-3.csv" | |
# Escrever cabeçalho no arquivo CSV | |
echo "first_name,middle_name,last_name,badge_count" > "$OUTPUT_FILE" | |
# Iniciar a contagem de páginas | |
PAGE=1 | |
while true; do | |
# Construir a URL completa | |
URL="${BASE_URL}${PAGE}&format=json" | |
# Fazer a solicitação HTTP e salvar o resultado | |
RESPONSE=$(curl -s "$URL") | |
# Verificar se a resposta contém dados | |
DATA=$(echo "$RESPONSE" | jq -r '.data | length') | |
if [ "$DATA" -eq 0 ]; then | |
# Se não houver dados, interrompe o loop | |
echo "Nenhum dado encontrado na página ${PAGE}. Interrompendo a execução." | |
break | |
fi | |
# Extrair e adicionar os dados ao CSV | |
echo "$RESPONSE" | jq -r '.data[] | [.first_name, .middle_name, .last_name, .badge_count] | @csv' >> "$OUTPUT_FILE" | |
echo "Processou página ${PAGE}" | |
# Incrementa a página | |
PAGE=$((PAGE + 1)) | |
done | |
echo "Concluído. Dados salvos em $OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment