Skip to content

Instantly share code, notes, and snippets.

@spg
Created November 22, 2019 20:38
Show Gist options
  • Save spg/1e6e3dfa711cd3dc427532480e9f986b to your computer and use it in GitHub Desktop.
Save spg/1e6e3dfa711cd3dc427532480e9f986b to your computer and use it in GitHub Desktop.
Get views
#!/bin/sh
GH_TOKEN=$1
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=1\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=2\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=3\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=4\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=5\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=6\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=7\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=8\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=9\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=10\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=11\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=12\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=13\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=14\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=15\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=16\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
echo "repo,count,uniques" >> views.csv
cat $repos.txt | while read reponame
do
DATA=`curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/repos/sindresorhus/$reponame/traffic/views?per=week | jq -r '"\(.count),\(.uniques)"'`
echo "$reponame,$DATA" >> views.csv
done
@spg
Copy link
Author

spg commented Nov 22, 2019

Prerequisites:

  • have jq installed

To run this script:

./getviews.sh {your GH API token}

e.g.:

./getviews.sh db18efb6684c052f242859ff253b75559d625706

@sindresorhus
Copy link

There's a tiny bug in a script: $repos.txt => repos.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment