diff options
Diffstat (limited to 'ingrex/praser.py')
-rwxr-xr-x | ingrex/praser.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ingrex/praser.py b/ingrex/praser.py new file mode 100755 index 0000000..732ab1b --- /dev/null +++ b/ingrex/praser.py | |||
@@ -0,0 +1,25 @@ | |||
1 | "Ingrex praser deal with message" | ||
2 | from datetime import datetime, timedelta | ||
3 | import platform | ||
4 | import os | ||
5 | import time | ||
6 | |||
7 | osname = platform.system() | ||
8 | if osname == "Linux": | ||
9 | os.environ['TZ'] = 'Asia/Shanghai' | ||
10 | time.tzset() | ||
11 | |||
12 | class Message(object): | ||
13 | "Message object" | ||
14 | def __init__(self, raw_msg): | ||
15 | self.raw = raw_msg | ||
16 | self.guid = raw_msg[0] | ||
17 | self.timestamp = raw_msg[1] | ||
18 | seconds, millis = divmod(raw_msg[1], 1000) | ||
19 | time = datetime.fromtimestamp(seconds) + timedelta(milliseconds=millis) | ||
20 | self.time = time.strftime('%Y/%m/%d %H:%M:%S:%f')[:-3] | ||
21 | self.text = raw_msg[2]['plext']['text'] | ||
22 | self.ptype = raw_msg[2]['plext']['plextType'] | ||
23 | self.team = raw_msg[2]['plext']['team'] | ||
24 | self.type = raw_msg[2]['plext']['markup'][1][1]['plain'] | ||
25 | |||