Skip to content

Instantly share code, notes, and snippets.

@stevesimmons
Created July 5, 2020 12:19
Show Gist options
  • Save stevesimmons/37a405caa802df7a331de69fa81cb7f7 to your computer and use it in GitHub Desktop.
Save stevesimmons/37a405caa802df7a331de69fa81cb7f7 to your computer and use it in GitHub Desktop.
Extract Github stars and dates they were starred
#!/bin/bash
# List starred GitHub repos and dates they were starred
# Usage: github-stars.sh > stars.txt
# Requires bash, sed, curl and jq.
# Note if unauthenticated, this has a rate limit of 60 requests per hour.
# So with 1000 starred repos 100 per page, this script can be called max 5 times in an hour.
# Overcome the rate limit by setting up an API token (Profile | Developer Options)
USER="GH_USERNAME"
AUTH="GH_USERNAME:GH_TOKEN"
PAGES=$(curl -s -u $AUTH -I https://api.github.com/users/$USER/starred?per_page=100 | sed -nr 's/^[lL]ink:.*page=([0-9]+).*/\1/p')
>&2 echo "Found $PAGES pages of starred repos for $USER."
for page in $(seq 1 $((PAGES+1)) ); do
>&2 echo "Extracting page $page"
declare -i ctr=0
curl -s -u $AUTH -H 'Accept: application/vnd.github.v3.star+json' "https://api.github.com/users/$USER/starred?page=$page&per_page=100&direction=asc" | jq -r '.[] | [ .starred_at[0:10], .repo.html_url ] | join(" ")' |
while read rp; do
((++ctr));
echo "$((ctr + (page - 1) * 100)): $rp";
done
# echo
done
>&2 echo "Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment