-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
58 lines (47 loc) · 2.1 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
import logging
import datetime
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
logger = logging.getLogger(__name__)
class TimestampExtension(Extension):
def __init__(self):
logger.info('init Timestamp Extension')
super(TimestampExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = []
if event.get_argument() is None:
dt = datetime.datetime.now()
ts = str(int(dt.timestamp()))
items.append(ExtensionResultItem(
icon='images/icon.png',
name="Timestamp: " + ts,
description=dt.strftime('%Y-%m-%d %H:%M:%S'),
highlightable=False,
on_enter=CopyToClipboardAction(ts)
))
return RenderResultListAction(items)
utcDt = datetime.datetime.utcfromtimestamp(int(event.get_argument()))
localDt = datetime.datetime.fromtimestamp(int(event.get_argument()))
formattedLocalDt = localDt.strftime('%Y-%m-%d %H:%M:%S')
formattedUtcDt = utcDt.strftime('%Y-%m-%d %H:%M:%S')
items.append(ExtensionResultItem(
icon='images/icon.png',
name="Local Time: " + formattedLocalDt,
highlightable=False,
on_enter=CopyToClipboardAction(formattedLocalDt)
))
items.append(ExtensionResultItem(
icon='images/icon.png',
name="UTC Time: " + formattedUtcDt,
highlightable=False,
on_enter=CopyToClipboardAction(formattedUtcDt)
))
return RenderResultListAction(items)
if __name__ == '__main__':
TimestampExtension().run()