-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
58 lines (39 loc) · 1.13 KB
/
__init__.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
# -*- coding: utf-8 -*-
from albert import *
import os
from time import sleep
import base64
__title__ = "base64 encoder/decoder"
__version__ = "0.1.0"
__triggers__ = ["encode ", "decode "]
__authors__ = "vykio"
iconPath = iconLookup("albert")
# Can be omitted
def initialize():
pass
# Can be omitted
def finalize():
pass
def makeItem(text: str, subtext: str):
return Item(
id=__title__,
icon=iconPath,
text=text,
subtext=subtext,
actions=[ClipAction("Copy to clipboard", text)]
)
def encode(text: str):
return base64.b64encode(bytes(text, 'utf-8'))
def decode(text: str):
return base64.b64decode(bytes(text, 'utf-8'))
def convert(trigger, value):
if trigger == 'encode ':
return [encode(value), "Convert text to base64"]
else:
return [decode(value), "Convert base64 to text"]
def handleQuery(query):
if query.isTriggered:
fields = query.string.split()
txt = " ".join(fields[:])
result = convert(query.trigger, txt)
return makeItem(result[0] if result[0] else result[1] , result[1] if result[0] else "by Vykio")