Advertisement
sxiii

Github Commiter Countries Parser Script Where Are They From

Aug 16th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. # This script is intended to see from which country some project committers are.
  3. # Requirements: Linux, Bash, curl, jq
  4. # Replace !!!GITHUB_TOKEN!!! variable below with your github token for this script to work.
  5.  
  6. # URL Specify
  7. url="https://api.github.com/repos"
  8. #user="/dogecoin"
  9. #repo="/dogecoin"
  10. user="/electroneum"
  11. repo="/electroneum-pool"
  12. section="/contributors"
  13. headers="authorization: Bearer !!!GITHUB_TOKEN!!!"
  14.  
  15. # Get project contributors
  16. echo $url$user$repo$section
  17.  
  18. curl -s --header "$headers" $url$user$repo$section | jq -r '.[].login' > users
  19. p=2; r="123"
  20.  
  21. until [[ $r == "" ]]; do
  22. r=$(curl -s --header "$headers" $url$user$repo$section?page=$p | jq -r '.[].login')
  23. printf "%s\n" $r >> users
  24. (( p++ ))
  25. done
  26.  
  27. ## printf "%s\n" $ActiveIPs > ActiveIPs.txt
  28.  
  29. echo "finished building user list of $repo, now loading users locations..."
  30.  
  31. # Get contributors countries
  32. while read p; do
  33. loc=$(curl -s --header "$headers" https://api.github.com/users/$p | jq -r '.location')
  34. echo $p : $loc
  35. done < ./users
  36.  
  37.  
  38. ## Some sources for ideas (you can safely remove that)
  39. # curl -s https://api.github.com/repos/dogecoin/dogecoin/contributors?page=2 | jq '.[].login'
  40. # Clean & neat way (requires curl and jq)
  41. # curl -s https://api.github.com/users/MarcoFalke | jq '.location'
  42. # Another option
  43. # curl -sb -H "Accept: application/json" https://api.github.com/users/MarcoFalke | jq '.location'
  44. # Dirty way (reqires curl, grep and awk)
  45. # curl https://github.com/MarcoFalke | grep "Home location" | awk -F\" '{ print $6 }' | awk -F: '{ print $2 }'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement