Skip to content

Instantly share code, notes, and snippets.

@NunoSempere
Created November 17, 2021 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NunoSempere/0959416ccf710a26974c8a95fb8431a6 to your computer and use it in GitHub Desktop.
Save NunoSempere/0959416ccf710a26974c8a95fb8431a6 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Defintions
fileName="list_of_users.txt"
fileNameResults="results.csv"
## Initialization
clear
rm -f "$fileNameResults"
echo "user, karma, wiki_edits" >> "$fileNameResults"
## Auxiliary function
function check_user(){
user="$1"
base_url="https://forum.effectivealtruism.org/users"
user_url="$base_url/$user"
wget "$user_url" -O "user.html" -q
# tidy -m "user.html" > /dev/null 2>&1
num_context=20
karma="$(cat user.html | grep -E -o ".{0,20}karma.{0,20}" | head -1 | sed 's|.*title="||' | sed "s| karma.*||" )"
## karma=$(cat user.html | grep " karma" | head -1 | sed 's|.*title="||' | sed "s| karma.*||")
wiki_edits="$(cat user.html | grep -E -o ".{0,20}wiki edit.{0,20}" | head -1 | sed 's|.*title="||' | sed "s| wiki edit.*||")"
echo "$user: $karma karma, $wiki_edits wiki edits"
echo "$user, $karma, $wiki_edits" >> "$fileNameResults"
}
## Main body
while IFS= read -r line; do
check_user "$line"
# echo "$line"
done < "$fileName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment