aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2017-02-05 20:39:30 -0800
committerRyan Huber <rhuber@gmail.com>2017-02-05 20:39:30 -0800
commit03a9a9f8dfbbbe1cf75d9861efdb0e2887c340d7 (patch)
tree717b7bb8d9d31745fa9e2bf5a9f1766efead4ef6 /wee_slack.py
parentd9ec818b440aafff1e8949592300d6b06a2333ba (diff)
downloadwee-slack-03a9a9f8dfbbbe1cf75d9861efdb0e2887c340d7.tar.gz
recorder improvement
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 1bdc244..504e829 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -5,6 +5,7 @@ import time
import json
import pickle
import sha
+import os
import re
import urllib
import sys
@@ -120,11 +121,10 @@ class EventRouter(object):
"""
self.recording = not self.recording
if self.recording:
- import os
if not os.path.exists(RECORD_DIR):
os.makedirs(RECORD_DIR)
- def record_event(self, message_json, file_name_field):
+ def record_event(self, message_json, file_name_field, subdir=None):
"""
complete
Called each time you want to record an event.
@@ -132,8 +132,14 @@ class EventRouter(object):
file_name_field is the json key whose value you want to be part of the file name
"""
now = time.time()
+ if subdir:
+ directory = "{}/{}".format(RECORD_DIR, subdir)
+ else:
+ directory = RECORD_DIR
+ if not os.path.exists(directory):
+ os.makedirs(directory)
mtype = message_json.get(file_name_field, 'unknown')
- f = open('{}/{}-{}.json'.format(RECORD_DIR, now, mtype), 'w')
+ f = open('{}/{}-{}.json'.format(directory, now, mtype), 'w')
f.write("{}".format(json.dumps(message_json)))
f.close()
@@ -211,7 +217,7 @@ class EventRouter(object):
}).jsonify()
message_json["wee_slack_metadata"] = metadata
if self.recording:
- self.record_event(message_json, 'type')
+ self.record_event(message_json, 'type', 'websocket')
self.receive_json(json.dumps(message_json))
except WebSocketConnectionClosedException:
#TODO: handle reconnect here
@@ -255,7 +261,7 @@ class EventRouter(object):
j["wee_slack_request_metadata"] = pickle.dumps(request_metadata)
self.reply_buffer.pop(request_metadata.response_id)
if self.recording:
- self.record_event(j, 'wee_slack_process_method')
+ self.record_event(j, 'wee_slack_process_method', 'http')
self.receive_json(json.dumps(j))
self.delete_context(data)
except: