Created
April 5, 2022 07:54
-
-
Save cassc/edaad47c7accc55d3602f8b830620101 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
# 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