93 lines
4.9 KiB
Bash
93 lines
4.9 KiB
Bash
#!/bin/bash
|
|
|
|
USER=$(whoami)
|
|
file_path="/home/$USER/Dokumente/api.keys"
|
|
|
|
if ! test -f $file_path; then
|
|
echo "Keine API Keys gefunden. Im Folgenden wird 'api.keys' Datei in /home/$USER/Dokumente/ abgelegt"
|
|
/usr/bin/touch /home/$USER/Dokumente/api.keys
|
|
/usr/bin/chown $USER:$USER /home/$USER/Dokumente/api.keys
|
|
MORE="y"
|
|
while [ $MORE == "y" ]; do
|
|
read -p "Bitte API Key eingeben: " API
|
|
API=${API:-}
|
|
echo $API >> /home/$USER/Dokumente/api.keys
|
|
read -p "Weitere API Keys eingeben? [y/N] " MORE
|
|
MORE=${MORE:-N}
|
|
done
|
|
fi
|
|
|
|
echo "Im Folgenden werden die Daten abgefragt nach denen gesucht werden soll. Bitte mit ENTER bestätigen."
|
|
read -p "Vorname [wird nicht gesucht wenn leer]: " VORNAME
|
|
VORNAME=${VORNAME:-}
|
|
read -p "Nachname [wird nicht gesucht wenn leer]: " NACHNAME
|
|
NACHNAME=${NACHNAME:-}
|
|
read -p "Username [wird nicht gesucht wenn leer]: " USERNAME
|
|
USERNAME=${USERNAME:-}
|
|
read -p "Email [wird nicht gesucht wenn leer]: " EMAIL
|
|
EMAIL=${EMAIL:-}
|
|
|
|
echo "Starte Suche, kann eine Weile dauern"
|
|
|
|
old_IFS="$IFS"
|
|
IFS=$'\n'
|
|
for line in $(cat "$file_path"); do
|
|
## WMDE-Survey Respondents ("Adressbuch")
|
|
rm -f /tmp/survey-$line-adress.json
|
|
echo "[]" > /tmp/survey-$line-adress.json
|
|
for POLL in $(curl -s -X GET -H "Authorization: Bearer $line" https://app.lamapoll.de/api/v2/polls?limit=1000 | jq -r '.[] | .id'); do
|
|
curl -s -X GET -H "Authorization: Bearer $line" https://app.lamapoll.de/api/v2/polls/${POLL}/respondents -s | jq -r '.' > /tmp/survey-$line-adress-$POLL.json
|
|
jq '. += (inputs)' /tmp/survey-$line-adress.json /tmp/survey-$line-adress-$POLL.json > /tmp/temp.json && mv /tmp/temp.json /tmp/survey-$line-adress.json && rm /tmp/survey-$line-adress-$POLL.json ; done
|
|
|
|
# filter surveys for values and extract id, pollId, name, email
|
|
rm -f /tmp/results-survey-$line-adress.json
|
|
echo "[]" > /tmp/results-survey-$line-adress.json
|
|
vars=("VORNAME" "NACHNAME" "USERNAME" "EMAIL")
|
|
for var_name in "${vars[@]}"; do
|
|
value="${!var_name}"
|
|
if [[ -n "$value" ]]; then
|
|
cat /tmp/survey-$line-adress.json | jq --arg TEST "$value" '.[] | select((.name | test($TEST; "i")) or (.email | test($TEST; "i"))) | {pollId, id, name, email}' > /tmp/survey-$line-adress-$var_name.json
|
|
jq '. += [(inputs)]' /tmp/results-survey-$line-adress.json /tmp/survey-$line-adress-$var_name.json > /tmp/temp.json && mv /tmp/temp.json /tmp/results-survey-$line-adress.json && rm /tmp/survey-$line-adress-$var_name.json
|
|
fi
|
|
done
|
|
# filter double finds
|
|
jq 'sort_by(.pollId, .id) | unique_by(.pollId, .id)' /tmp/results-survey-$line-adress.json > /tmp/tmp.json && mv /tmp/tmp.json /tmp/results-survey-$line-adress.json
|
|
|
|
## WMDE-Survey Results ("Freitextsuche")
|
|
rm -f /tmp/survey-$line-freetext.json
|
|
echo "[]" > /tmp/survey-$line-freetext.json
|
|
for POLL in $(curl -s -X GET -H "Authorization: Bearer $line" https://app.lamapoll.de/api/v2/polls?limit=1000 | jq -r '.[] | .id'); do
|
|
curl -s -X GET -H "Authorization: Bearer $line" https://app.lamapoll.de/api/v2/polls/${POLL}/results -s | jq --arg POLL "${POLL}" -r '. | .pollId = $POLL' > /tmp/survey-$line-freetext-$POLL.json
|
|
jq '. += [(inputs)]' /tmp/survey-$line-freetext.json /tmp/survey-$line-freetext-$POLL.json > /tmp/temp.json && mv /tmp/temp.json /tmp/survey-$line-freetext.json && rm /tmp/survey-$line-freetext-$POLL.json ; done
|
|
|
|
cat /tmp/survey-$line-freetext.json | tr -cd '\11\12\40-\176' > /tmp/survey-$line-freetext-removed.json
|
|
rm /tmp/survey-$line-freetext.json
|
|
mv /tmp/survey-$line-freetext-removed.json /tmp/survey-$line-freetext.json
|
|
|
|
rm -f /tmp/results-survey-$line-freetext.json
|
|
echo "[]" > /tmp/results-survey-$line-freetext.json
|
|
vars=("VORNAME" "NACHNAME" "USERNAME" "EMAIL")
|
|
for var_name in "${vars[@]}"; do
|
|
value="${!var_name}"
|
|
if [[ -n "$value" ]]; then
|
|
cat /tmp/survey-$line-freetext.json | jq --arg TEST "$value" '.[] | {name: .name, pollId: .pollId, results: .results[] | select(.groups[].labels[] | test($TEST; "i")) | {question: .question, questionId: .questionId, labels: [.groups[].labels[] | select(test($TEST; "i"))]}}' > /tmp/survey-$line-freetext-$var_name.json
|
|
jq '. += [(inputs)]' /tmp/results-survey-$line-freetext.json /tmp/survey-$line-freetext-$var_name.json > /tmp/temp.json && mv /tmp/temp.json /tmp/results-survey-$line-freetext.json && rm /tmp/survey-$line-freetext-$var_name.json
|
|
fi
|
|
done
|
|
done
|
|
IFS="$old_IFS"
|
|
|
|
old_IFS="$IFS"
|
|
IFS=$'\n'
|
|
rm -f /tmp/resultfile.json 2>&1 >/dev/null
|
|
touch /tmp/resultfile.json
|
|
for line in $(cat "$file_path"); do
|
|
cat /tmp/results-survey-$line-adress.json >> /tmp/resultfile.json
|
|
echo "" >> /tmp/resultfile.json
|
|
cat /tmp/results-survey-$line-freetext.json >> /tmp/resultfile.json
|
|
echo "" >> /tmp/resultfile.json
|
|
done
|
|
IFS="$old_IFS"
|
|
/usr/bin/gnome-text-editor /tmp/resultfile.json
|
|
rm -f /tmp/resultfile.json
|
|
rm -f /tmp/results-survey*.json |