Skip to content

Instantly share code, notes, and snippets.

@djamseed
Created January 10, 2024 23:36
Show Gist options
  • Save djamseed/751da3f4595d20f98dcf451f4d58bebb to your computer and use it in GitHub Desktop.
Save djamseed/751da3f4595d20f98dcf451f4d58bebb to your computer and use it in GitHub Desktop.
import sys
import webbrowser
def google_search(query):
base_url = "https://www.google.com/search?q="
query_string = query.replace(" ", "+")
# show results from the sites below
sites = ["dev.to", "github.com", "medium.com", "stackoverflow.com", "youtube.com"]
site_string = " OR ".join(["site:" + site for site in sites])
query_string += " (" + site_string + ")"
search_url = base_url + query_string
webbrowser.open_new_tab(search_url)
print(search_url)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: search <query>")
sys.exit(1)
query = " ".join(sys.argv[1:])
google_search(query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment