add: search script

This commit is contained in:
Léana 江 2023-11-29 14:40:36 +01:00 committed by Léana 江
parent df3001dbab
commit 2928cfe605
3 changed files with 52 additions and 25 deletions

37
.local/bin/search.py Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python3
import argparse
import os
SEARX = "https://searxng.earth2077.fr/search?q={query}"
INVIDIOUS = "https://invidious.earth2077.fr/search?q={query}"
GITHUB = "https://github.com/search?q={query}&type=repositories"
FORGEJO = "https://git.earth2077.fr/?repo-search-query={query}"
parser = argparse.ArgumentParser(description="Search the web, simply")
parser.add_argument("-m", "--motor", type=str, nargs=1, help="motor")
parser.add_argument("query", type=str, nargs="*", help="query")
args = parser.parse_args()
motor = ""
if not args.motor:
motor = SEARX
else:
match args.motor[0]:
case "yt":
motor = INVIDIOUS
case "fj":
motor = FORGEJO
case "gh":
motor = GITHUB
case _:
motor = SEARX
query = " ".join(args.query).replace(" ", "%20")
link = motor[:].replace("{query}", query)
os.system(f"open {link}")