Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active October 18, 2024 06:16
Show Gist options
  • Save wilmoore/6747ac4cd6999f18e009fe26dfd363ad to your computer and use it in GitHub Desktop.
Save wilmoore/6747ac4cd6999f18e009fe26dfd363ad to your computer and use it in GitHub Desktop.
Software Engineering :: Source Control :: VCS :: Git :: Managed Hosting Platform :: GitHub :: Gist :: API :: Scripting

Software Engineering :: Source Control :: VCS :: Git :: Managed Hosting Platform :: GitHub :: Gist :: API :: Scripting

⪼ Made with 💜 by Polyglot.

content
related

source

Request

export $(grep -v '^#' .env | xargs) && curl -I --request GET \
  --url 'https://api.github.com/gists?per_page=100&page=1' \
  --header 'Accept: application/vnd.github+json' \
  --header "Authorization: Bearer ${GIST_API_KEY}" \
  --header 'X-GitHub-Api-Version: 2022-11-28'

Response

HTTP/2 200
date: Tue, 03 Sep 2024 22:43:55 GMT
content-type: application/json; charset=utf-8
content-length: 238838
cache-control: private, max-age=60, s-maxage=60
vary: Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With
etag: "f764aa7f51cd5f4889836b77a71a33623e136bf03895e1d5ac6704e661916ded"
x-oauth-scopes: gist
x-accepted-oauth-scopes:
github-authentication-token-expiration: 2024-10-22 21:29:47 UTC
x-github-media-type: github.v3; format=json
link: <https://api.github.com/gists?per_page=100&page=2>; rel="next", <https://api.github.com/gists?per_page=100&page=116>; rel="last"
x-github-api-version-selected: 2022-11-28
x-ratelimit-limit: 5000
x-ratelimit-remaining: 4945
x-ratelimit-reset: 1725405732
x-ratelimit-used: 55
x-ratelimit-resource: core
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
x-github-request-id: CFBA:29236E:E0186AD:1ADDDFCE:66D79128
server: github.com

Total Number of Pages

Script

total_pages=$(export $(grep -v '^#' .env | xargs) && curl -Is --request GET \
  --url 'https://api.github.com/gists?per_page=100&page=1' \
  --header 'Accept: application/vnd.github+json' \
  --header "Authorization: Bearer ${GIST_API_KEY}" \
  --header 'X-GitHub-Api-Version: 2022-11-28' | grep -i "^Link:" | cut -d '=' -f 6 | cut -d '>' -f 1)
  
echo "Number of pages: $total_pages"

Output

Number of pages: 116

Calculate Total Number of Gists

Script

total_pages=$(export $(grep -v '^#' .env | xargs) && curl -Is --request GET \
  --url 'https://api.github.com/gists?per_page=100&page=1' \
  --header 'Accept: application/vnd.github+json' \
  --header "Authorization: Bearer ${GIST_API_KEY}" \
  --header 'X-GitHub-Api-Version: 2022-11-28' | grep -i "^Link:" | cut -d '=' -f 6 | cut -d '>' -f 1)

total_gists=$((total_pages * 100))
echo "Approximate number of gists: $total_gists"

Output

Approximate number of gists: 11600

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