forked from python-cn/slack_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
42 lines (34 loc) · 1.05 KB
/
manage.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
# coding=utf-8
import json
from pprint import pprint
from flask import current_app
from flask_script import Manager, Server
from slack_bot.app import create_app
manager = Manager(create_app)
manager.add_option('-c', '--config', dest='config', required=False)
manager.add_command(
'runserver', Server(use_debugger=True, use_reloader=True, host='0.0.0.0')
)
@manager.option('text')
def send(text):
"""Send text to slack callback url"""
data = current_app.config['TEST_DATA']
uri = current_app.config['SLACK_CALLBACK']
client = current_app.test_client()
data['text'] = text
rv = client.post(uri, data=data)
if rv.status_code == 200:
body = rv.data
if not body:
print('Response body is empty!')
return
obj = json.loads(body)
if not obj.get('attachments'):
obj = obj['text']
print(obj)
else:
pprint(obj)
else:
print('Error!\nstatus code: %s\nbody: %s' % (rv.status_code, rv.data))
if __name__ == '__main__':
manager.run()