diff options
author | Jinwei Zhao <[email protected]> | 2017-01-02 22:05:44 +0800 |
---|---|---|
committer | Jinwei Zhao <[email protected]> | 2017-01-02 22:05:44 +0800 |
commit | cb52be3055b9ef05b5d1ead9431fdd69834ee3ba (patch) | |
tree | 82447e7e18dc3e2dfc7fa32a076ee5d016e64e2b /ingrex/praser.py | |
parent | cff3f50819073668391465dd8121bf9e0b8a7c33 (diff) | |
download | COMM2TG-cb52be3055b9ef05b5d1ead9431fdd69834ee3ba.tar.gz |
init
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 | |||