-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
52 lines (37 loc) · 1.54 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import logging
import urllib
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.OpenUrlAction import OpenUrlAction
# Use this to log messages
LOGGER = logging.getLogger(__name__)
# to encode URL
def urlencode(qp):
return urllib.urlencode(qp)
class BraveExt(Extension):
def __init__(self):
super(BraveExt, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = list()
if event.get_argument():
LOGGER.info('Showing Brave search for "{}"'.format(
event.get_argument()))
items.append(ExtensionResultItem(
icon='images/icon.png',
name='Search on Brave',
description='Search for "{}".'.format(event.get_argument()),
on_enter=OpenUrlAction(
'https://search.brave.com/search/?q={}'.format(event.get_argument())
#{}'.format(
# urlencode({'q': event.get_argument(), 's': 'all'})
)#)
)
)
return RenderResultListAction(items)
if __name__ == '__main__':
BraveExt().run()