-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
92 lines (68 loc) · 3.69 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
import logging
from time import sleep
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.ExtensionCustomAction import ExtensionCustomAction
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
from ulauncher.api.shared.action.DoNothingAction import DoNothingAction
logger = logging.getLogger(__name__)
import kanboard
from requests.auth import HTTPBasicAuth
from requests import get as g
from requests import post as p
class Kanboard(Extension):
def __init__(self):
super(Kanboard, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
self.subscribe(ItemEnterEvent, ItemEnterEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
items = []
query = event.get_argument() or ""
split_query = query.partition(" ")
keyword = split_query[0]
data = split_query[2]
if keyword != "add":
items.append(ExtensionResultItem(icon='images/icon.png',
name='Please use the keyword "add"',
description='Example: add %s' % data,
highlightable=False,
on_enter=DoNothingAction()))
return RenderResultListAction(items)
else:
items.append(ExtensionResultItem(icon='images/icon.png',
name="Press enter to add: %s" % (data),
highlightable=False,
on_enter=ExtensionCustomAction(data, keep_app_open=True)))
return RenderResultListAction(items)
class ItemEnterEventListener(EventListener):
def on_event(self, event, extension):
items = []
data = event.get_data()
setting_url = extension.preferences['setting_url']
setting_user = extension.preferences['setting_user']
setting_pass = extension.preferences['setting_pass']
setting_project = extension.preferences['project_id']
url = setting_url + "/jsonrpc.php"
payload = "{\"jsonrpc\": \"2.0\", \"method\": \"createTask\", \"id\": 1, \"params\": {\"title\": \"" + data + "\", \"project_id\": " + setting_project + "}}"
r = p(url, data=payload, auth=HTTPBasicAuth(setting_user, setting_pass))
# response = r.json()
if r.status_code == 200:
items.append(ExtensionResultItem(icon='images/icon.png',
name="Added %s" % data,
highlightable=False,
on_enter=HideWindowAction()))
return RenderResultListAction(items)
else:
items.append(ExtensionResultItem(icon='images/icon.png',
name="Error connecting to API.",
highlightable=False,
on_enter=HideWindowAction()))
return RenderResultListAction(items)
if __name__ == '__main__':
Kanboard().run()