|
|
@@ -0,0 +1,46 @@ |
|
|
|
#!/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 '<div id="org-repositories"' in r.text: |
|
|
|
# Organisation, ?page=2 pagination |
|
|
|
page = 1 |
|
|
|
while True: |
|
|
|
for m in re.finditer(r'<a itemprop="name codeRepository"\s(?:[^>]*\s)?data-hovercard-url="/([^/>"]+/[^/>"]+)/hovercard"', r.text): |
|
|
|
print(m.group(1)) |
|
|
|
if '<a class="next_page"' not in r.text: |
|
|
|
# End of pagination |
|
|
|
break |
|
|
|
page += 1 |
|
|
|
r = get(f'https://github.com/{user}?page={page}') |
|
|
|
else: |
|
|
|
# User, ?tab=repositories + cursor pagination |
|
|
|
r = get(f'https://github.com/{user}?tab=repositories') |
|
|
|
while True: |
|
|
|
for m in re.finditer(r'<a href="/([^/>"]+/[^/>"]+)" itemprop="name codeRepository"(\s[^>]*)?>', r.text): |
|
|
|
print(m.group(1)) |
|
|
|
if not (m := re.search(r'<a\s(?:[^>]*\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') |