Skip to content

Instantly share code, notes, and snippets.

@cassc
Created April 5, 2022 07:54
Show Gist options
  • Save cassc/edaad47c7accc55d3602f8b830620101 to your computer and use it in GitHub Desktop.
Save cassc/edaad47c7accc55d3602f8b830620101 to your computer and use it in GitHub Desktop.
# github code search
#
# Usage:
# python3 github-search.py -l rs -t Code ethers contract
import subprocess
from urllib.parse import quote_plus
import argparse
BROWSER_CLI = 'brave'
TEMPLATE_URL = 'https://github.com/search?q={}&type={}&l={}'
ap = argparse.ArgumentParser()
ap.add_argument('-l', '--language', help='Programming language (by extension)', type=str)
ap.add_argument('-t', '--type', help='Type of search', type=str, default='Code')
ap.add_argument('words', metavar='W', type=str, nargs='+', help='Keywords to search for')
args = vars(ap.parse_args())
def gen_url(lang, tpe, words):
query = '+'.join([quote_plus(w) for w in words])
return TEMPLATE_URL.format(query, quote_plus(tpe), quote_plus(lang or ''))
if __name__ == '__main__':
lang = args['language']
tpe = args['type']
words = args['words']
url = gen_url(lang, tpe, words)
subprocess.call([BROWSER_CLI, url])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment