Created
February 19, 2023 12:02
-
-
Save p3r7/881def574c80d9063f983b7ebc823aca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
## ------------------------------------------------------------------------ | |
## imports | |
import re | |
from pprint import pprint | |
import requests | |
## ------------------------------------------------------------------------ | |
## helper fns | |
def alias_w_no_at(alias): | |
if alias.startswith('@'): | |
alias = alias[1:] | |
return alias | |
def author_name_as_only_alias(name): | |
alias_search = re.search('.*\((.*)\)', name) | |
alias = name | |
if alias_search: | |
alias = alias_search.group(1) | |
return alias_w_no_at(alias) | |
def normalize_author(a): | |
authors = [] | |
if '&' in a: | |
authors = [author for author in a.split('&') if len(author.strip()) > 1] | |
else: | |
authors = a.split(',') | |
authors = [author_name_as_only_alias(author.strip()) for author in authors] | |
if len(authors) == 1: | |
return authors[0] | |
return authors | |
## ------------------------------------------------------------------------ | |
## main | |
r = requests.get('https://raw.githubusercontent.com/monome/norns-community/main/community.json', headers={'Accept': 'application/json'}) | |
script_index = r.json() | |
for i, script in enumerate(script_index['entries']): | |
script['author'] = normalize_author(script['author']) | |
script_index['entries'] = sorted(script_index['entries'], key=lambda script: script['project_name']) | |
pprint(script_index) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment