this is a very simple messge service with static file written in py
非常简单的基于静态文件的使用py写的消息服务
msg type code
信息类型码
code 代码 | type 类型 | describe 说明 |
---|---|---|
0 | NOTICE | notice msg should be this type 通知信息应为此种类型 |
1 | UPDATE | update avaliable 有升级可用 |
2 | DOWN | main service down 主服务下线 |
3 | UP | main service up 主服务上线 |
python msgman.py list
this command should return a msg list like:
这个命令将会返回消息列表如:
List of msgs
Index Type Time Content
0 NOTICE 2017-07-03 20:09:32 {b'msg': b'a msg here'}
1 UPDATE 2017-07-03 20:10:15 {b'addr': b'https://m.cust.edu.cn/app/somenewver.apk'}
2 DOWN 2017-07-03 20:10:35 None
python msgman.py add <type code> [msg content(payload,Nullable)]
add msg to msgfile, type code should be number as described, content should be json-serializable
添加消息到消息文件,类型码应为以上中的数字,内容应为可被json解码的
example 例如:
rem (in cmd on windows)
python msgman.py add 0 "{\"msg\":\"a msg here\"}"
python msgman.py add 1 "{\"addr\":\"https://m.cust.edu.cn/app/somenewver.apk\"}"
python msgman.py add 2
# at a bash shell:
./msgman.py add 0 '{"msg":"a msg here"}'
./msgman.py add 1 '{"addr":"https://m.cust.edu.cn/app/somenewver.apk"}'
./msgman.py add 2
if no error, the result will contain "done" 如果没有问题,执行结果将会包含 “done”
python msgman.py del <index number>
remove a msg at index <index number>
删除索引号为的一条消息
例如
python msgman.py list
List of msgs
Index Type Time Content
0 NOTICE 2017-07-03 20:09:32 {b'msg': b'a msg here'}
1 UPDATE 2017-07-03 20:10:15 {b'addr': b'https://m.cust.edu.cn/app/somenewver.apk'}
2 DOWN 2017-07-03 20:10:35 None
python msgman.py del 2
done.
python msgman.py list
List of msgs
Index Type Time Content
0 NOTICE 2017-07-03 20:09:32 {b'msg': b'a msg here'}
1 UPDATE 2017-07-03 20:10:15 {b'addr': b'https://m.cust.edu.cn/app/somenewver.apk'}
use any way like http/ftp to get the msgfile, then json decode it, use it as common json file. if msgpack option enabled, decode msgpack first.
使用任何方式获取消息文件,然后json解码后使用,如果开启了msgpack选项,先解码msgpack。
almost nothing to configure, no need to change default config
基本上没啥好配置的,不需要默认配置修改
config.py:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#simple message service config file
msgname='./msg.json' # msg file path 消息文件路径
ver='0.0.1' #version code 版本号,可能会向后兼容用
USE_MSGPACK=True #use msgpack 是否开启msgpack
if USE_MSGPACK :
msgname=msgname.replace('json','bin') # automatic change file extname to bin when msgpack enabled 当msgpack开启时自动修改扩展名到bin