-
Notifications
You must be signed in to change notification settings - Fork 1
/
slack_setup.py
49 lines (42 loc) · 1.29 KB
/
slack_setup.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
# encoding: utf-8
import sys
sys.path.append("./lib")
from workflow import Workflow, ICON_WARNING, ICON_INFO, web, Variables
import os
import datetime
import calendar
import argparse
import requests
log = None
from workflow.notify import notify
from workflow import PasswordNotFound
def main(wf):
log = wf.logger
parser = argparse.ArgumentParser()
parser.add_argument('token', nargs="?")
parser.add_argument('--clear', dest='clear', default=False,
action='store_true')
parser.add_argument('--echo', dest='echo', default=False,
action='store_true')
args = parser.parse_args(wf.args)
if args.clear:
try:
wf.delete_password('slack_token')
except PasswordNotFound :
pass
notify('Deleted.', 'Token deleted')
return 0
elif args.token:
wf.save_password('slack_token', args.token)
notify('Saved.',
'Token saved')
return 0
elif args.echo:
log.debug(wf.get_password('slack_token'))
else:
notify('Problem in saving the token.',
'Please use slacksetup to set your Slack API key. Received %s' % args.token)
return 0
if __name__ == u"__main__":
wf = Workflow()
sys.exit(wf.run(main))