|
|
@@ -5,8 +5,17 @@ import requests |
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
GIT_URLS_OPTION = '--git-urls' |
|
|
|
GITGUD_COMPLETE_ITEMS_OPTION = '--gitgud-complete-items' |
|
|
|
MODES = (GIT_URLS_OPTION, GITGUD_COMPLETE_ITEMS_OPTION) |
|
|
|
|
|
|
|
|
|
|
|
mode = None |
|
|
|
users = sys.argv[1:] |
|
|
|
assert users, 'Usage: github-list-repos USER [USER...]' |
|
|
|
if users and users[0] in MODES: |
|
|
|
mode = users[0] |
|
|
|
users = users[1:] |
|
|
|
assert users and (mode is None or mode in MODES) and not users[0].startswith('--'), f'Usage: github-list-repos [{" | ".join(MODES)}] USER [USER...]' |
|
|
|
|
|
|
|
|
|
|
|
def get(url): |
|
|
@@ -21,6 +30,16 @@ def get(url): |
|
|
|
return r |
|
|
|
|
|
|
|
|
|
|
|
def p(repoName): |
|
|
|
if mode is None: |
|
|
|
print(f'https://github.com/{repoName}') |
|
|
|
elif mode == GIT_URLS_OPTION: |
|
|
|
print(f'https://github.com/{repoName}.git') |
|
|
|
print(f'https://github.com/{repoName}.wiki.git') |
|
|
|
elif mode == GITGUD_COMPLETE_ITEMS_OPTION: |
|
|
|
print(f'web:complete:{repoName}') |
|
|
|
|
|
|
|
|
|
|
|
for user in users: |
|
|
|
r = get(f'https://github.com/{user}') |
|
|
|
if '<div id="org-repositories"' in r.text: |
|
|
@@ -28,7 +47,7 @@ for user in users: |
|
|
|
page = 1 |
|
|
|
while True: |
|
|
|
for m in re.finditer(r'<a itemprop="name codeRepository"\s(?:[^>]*\s)?data-hovercard-url="/([^/>"]+/[^/>"]+)/hovercard"', r.text): |
|
|
|
print(f'https://github.com/{m.group(1)}') |
|
|
|
p(m.group(1)) |
|
|
|
if '<a class="next_page"' not in r.text: |
|
|
|
# End of pagination |
|
|
|
break |
|
|
@@ -39,7 +58,7 @@ for user in users: |
|
|
|
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(f'https://github.com/{m.group(1)}') |
|
|
|
p(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 |
|
|
|