Skip to content

Instantly share code, notes, and snippets.

@spg
Created November 22, 2019 20:38
Show Gist options
  • Select an option

  • Save spg/1e6e3dfa711cd3dc427532480e9f986b to your computer and use it in GitHub Desktop.

Select an option

Save spg/1e6e3dfa711cd3dc427532480e9f986b to your computer and use it in GitHub Desktop.

Revisions

  1. spg created this gist Nov 22, 2019.
    28 changes: 28 additions & 0 deletions getviews.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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