dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

search_engines.py (1006B)


      1 from .user_settings import get_list_from_csv
      2 from talon import Module, Context
      3 from urllib.parse import quote_plus
      4 import webbrowser
      5 
      6 mod = Module()
      7 mod.list(
      8     "search_engine",
      9     desc="A search engine.  Any instance of %s will be replaced by query text",
     10 )
     11 
     12 _search_engine_defaults = {
     13     "amazon": "https://www.amazon.com/s/?field-keywords=%s",
     14     "google": "https://www.google.com/search?q=%s",
     15     "map": "https://maps.google.com/maps?q=%s",
     16     "scholar": "https://scholar.google.com/scholar?q=%s",
     17     "wiki": "https://en.wikipedia.org/w/index.php?search=%s",
     18 }
     19 
     20 ctx = Context()
     21 ctx.lists["self.search_engine"] = get_list_from_csv(
     22     "search_engines.csv",
     23     headers=("URL Template", "Name"),
     24     default=_search_engine_defaults,
     25 )
     26 
     27 
     28 @mod.action_class
     29 class Actions:
     30     def search_with_search_engine(search_template: str, search_text: str):
     31         """Search a search engine for given text"""
     32         url = search_template.replace("%s", quote_plus(search_text))
     33         webbrowser.open(url)