Browse Source

Make --name a normal mode

master
JustAnotherArchivist 1 year ago
parent
commit
75999e969c
1 changed files with 7 additions and 8 deletions
  1. +7
    -8
      github-list-repos

+ 7
- 8
github-list-repos View File

@@ -10,19 +10,16 @@ import time

GIT_URLS_OPTION = '--git-urls'
GITGUD_COMPLETE_ITEMS_OPTION = '--gitgud-complete-items'
MODES = (GIT_URLS_OPTION, GITGUD_COMPLETE_ITEMS_OPTION)
NAME_OPTION = '--name'
MODES = (GIT_URLS_OPTION, GITGUD_COMPLETE_ITEMS_OPTION, NAME_OPTION)


mode = None
name = False
users = sys.argv[1:]
if users and users[0] == '--name':
name = True
users = users[1:]
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 [--name] [{" | ".join(MODES)}] USER [USER...]'
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):
@@ -51,7 +48,7 @@ for user in users:
r = get(f'https://github.com/{user}')
if '<div id="org-repositories"' in r.text:
# Organisation, complete list under /orgs/ with ?page=2 pagination
if name:
if mode == NAME_OPTION:
musername = re.search(r'<meta property="profile:username" content="([^"]*)" />', r.text)
if not musername:
print('Error: could not find profile:username meta tag', file = sys.stderr)
@@ -62,6 +59,7 @@ for user in users:
sys.exit(1)
print(html.unescape(musername.group(1).strip().replace('\n', ' ').replace('\r', ' ')))
print(html.unescape(mfullname.group(1).strip().replace('\n', ' ').replace('\r', ' ')))
sys.exit(0)
r = get(f'https://github.com/orgs/{user}/repositories')
page = 1
while True:
@@ -74,7 +72,7 @@ for user in users:
r = get(f'https://github.com/orgs/{user}/repositories?page={page}')
else:
# User, ?tab=repositories + cursor pagination
if name:
if mode == NAME_OPTION:
musername = re.search(r'<span\s(?:[^>]*\s)?class="(?:[^"]*\s)?vcard-username(?:\s[^"]*)?"(?:\s[^>]*)?>(.*?)</span>', r.text, flags = re.DOTALL)
if not musername:
print('Error: could not find vcard-username span', file = sys.stderr)
@@ -85,6 +83,7 @@ for user in users:
fullname = ''
print(html.unescape(musername.group(1).strip()).replace('\n', ' ').replace('\r', ' '))
print(fullname.replace('\n', ' ').replace('\r', ' '))
sys.exit(0)
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):


Loading…
Cancel
Save