-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (28 loc) · 924 Bytes
/
utils.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
# -*- coding: utf-8 -*-
import json
def package_msg(key, msg):
packed_msg = {}
packed_msg[key] = msg
return json.dumps(packed_msg)
def package_sys_msg(key, msg):
packed_msg = {}
packed_msg['SysMsg'] = {key: msg}
return json.dumps(packed_msg)
def package_public_chat_msg(sender, msg):
packed_msg = {}
packed_msg['ChatMsg'] = {'toAll': [sender, msg]}
return json.dumps(packed_msg)
def package_private_chat_msg(sender, receiver, msg):
packed_msg = {}
packed_msg['ChatMsg'] = {'toClient': [sender, receiver, msg]}
return json.dumps(packed_msg)
def convert_seconds_to_hms_fmt(seconds):
'''
convert seconds to day, hour, seconds format
:return: day, hour, seconds format in str
'''
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
# time_str = str("%02dh-%02dm-%02ds" % (h, m, s))
time_str = str("%02dh-%02dm" % (h, m))
return time_str