import itertools import requests def iter_repos(username): for page in itertools.count(1): response = requests.get( f'https://api.github.com/users/{username}/repos', { 'page': page, 'per_page': 100, 'sort': 'created', }, ) response.raise_for_status() repos = response.json() for repo in repos: if not repo['fork'] and not repo['archived']: yield repo if len(repos) < 100: break if __name__ == '__main__': print('---\ntitle: projects\n---') prev_year = None for repo in iter_repos('xi'): year = repo['created_at'][:4] if year != prev_year: print(f'\n## {year}\n') prev_year = year print('- [{name}]({html_url}) - {description}'.format(**repo))