#!/usr/bin/env python3 import logging import re import requests import sys users = sys.argv[1:] assert users, 'Usage: github-list-repos USER [USER...]' def get(url): while True: logging.info(f'Fetching {url}') r = requests.get(url, headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0'}) if r.status_code == 429: logging.warning(f'Got 429, sleeping and retrying') time.sleep(5) else: break return r for user in users: r = get(f'https://github.com/{user}') if '
]*\s)?data-hovercard-url="/([^/>"]+/[^/>"]+)/hovercard"', r.text): print(f'https://github.com/{m.group(1)}') if '"]+)" itemprop="name codeRepository"(\s[^>]*)?>', r.text): print(f'https://github.com/{m.group(1)}') if not (m := re.search(r']*\s)?href="https://github\.com/[^/?"]+\?after=([^&]+)&tab=repositories"(?:\s[^>]*)?>', r.text)): # End of pagination break r = get(f'https://github.com/{user}?after={m.group(1)}&tab=repositories')