-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
74 lines (60 loc) · 3.38 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
import logging
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.CopyToClipboardAction import CopyToClipboardAction
import datetime
logger = logging.getLogger(__name__)
class DemoExtension(Extension):
def __init__(self):
super(DemoExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = []
logger.info('preferences %s' % json.dumps(extension.preferences))
# data = event.get_data()
# print("my event", event.get_keyword())
# print('{0:%Y-%m-%d}'.format(datetime.datetime.now()))
items.append(ExtensionResultItem(icon='images/icon.png',
name='YYYY-MM-DD',
description='Enter to copy to the clipboard',
on_enter=CopyToClipboardAction('{0:%Y-%m-%d}'.format(datetime.datetime.now()))))
items.append(ExtensionResultItem(icon='images/icon.png',
name='HH:mm',
description='Enter to copy to the clipboard',
on_enter=CopyToClipboardAction(
'{0:%H:%M}'.format(datetime.datetime.now()))))
items.append(ExtensionResultItem(icon='images/icon.png',
name='YYYY-MM-DD HH:mm',
description='Enter to copy to the clipboard',
on_enter=CopyToClipboardAction(
'{0:%Y-%m-%d %H:%M}'.format(datetime.datetime.now()))))
now = datetime.datetime.now()
time_intervals = [
(0, 3), (3, 6), (6, 9), (9, 12), (12, 15), (15, 18), (18, 21), (21,)
]
current_time_interval = ''
for i in time_intervals:
if i[0] == 21:
current_time_interval = '21-24'
break
if i[0] <= now.hour and now.hour < i[1]:
current_time_interval = '{}-{}'.format(i[0], i[1])
break
items.append(ExtensionResultItem(icon='images/icon.png',
name='HH1-HH2',
description='Enter to copy to the clipboard',
on_enter=CopyToClipboardAction(
current_time_interval)))
items.append(ExtensionResultItem(icon='images/icon.png',
name='HH1-HH2: HH:mm',
description='Enter to copy to the clipboard',
on_enter=CopyToClipboardAction(
'%s: %s' % (current_time_interval,'{0:%H:%M}'.format(datetime.datetime.now())))))
return RenderResultListAction(items)
if __name__ == '__main__':
DemoExtension().run()