-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
51 lines (36 loc) · 1.5 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
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 DUCKExtension(Extension):
def __init__(self):
super(DUCKExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = list()
if event.get_argument():
LOGGER.info('Showing DuckDuckGo search for "{}"'.format(
event.get_argument()))
items.append(ExtensionResultItem(
icon='images/icon.png',
name='Search on Duckduckgo',
description='Search for "{}".'.format(event.get_argument()),
on_enter=OpenUrlAction(
'https://duckduckgo.com/?{}'.format(
urlencode({'q': event.get_argument(), 's': 'all'})
))
)
)
return RenderResultListAction(items)
if __name__ == '__main__':
DUCKExtension().run()