Skip to content

Instantly share code, notes, and snippets.

@sunnydsouza
Created January 6, 2024 05:53
Show Gist options
  • Save sunnydsouza/b4a761e8a94f2fdad499753b5227155b to your computer and use it in GitHub Desktop.
Save sunnydsouza/b4a761e8a94f2fdad499753b5227155b to your computer and use it in GitHub Desktop.
import requests
# Replace 'your-username' with your actual GitHub username
# Replace 'your-github-token' with your actual GitHub personal access token
USERNAME = "your-username"
TOKEN = "your-github-token"
# The GitHub API endpoint for user repositories
GITHUB_REPO_API = f"https://api.github.com/users/{USERNAME}/repos"
# Set up the session with the auth token
session = requests.Session()
session.headers.update({'Authorization': f'token {TOKEN}'})
def get_github_pages_repos(api_url):
# List to hold repositories with GitHub Pages enabled
pages_repos = []
# Fetch the repositories from GitHub API
while True:
response = session.get(api_url)
response.raise_for_status() # Raise an error if the request failed
repos = response.json()
# Check each repository for GitHub Pages configuration
for repo in repos:
pages_url = f"https://api.github.com/repos/{repo['full_name']}/pages"
pages_response = session.get(pages_url)
if pages_response.status_code == 200:
pages_info = pages_response.json()
if 'html_url' in pages_info:
pages_repos.append((repo['full_name'], pages_info['html_url']))
# Check if there is a 'next' page, otherwise break the loop
if 'next' in response.links:
api_url = response.links['next']['url']
else:
break
return pages_repos
# Get the list of repositories with GitHub Pages enabled
github_pages_repos = get_github_pages_repos(GITHUB_REPO_API)
for full_name, html_url in github_pages_repos:
print(f"GitHub Pages is enabled for {full_name} at {html_url}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment