Skip to content

Instantly share code, notes, and snippets.

@dixyes
Last active July 3, 2017 12:48
Show Gist options
  • Save dixyes/95a00a97496695dcea15a0b8d2b9c60d to your computer and use it in GitHub Desktop.
Save dixyes/95a00a97496695dcea15a0b8d2b9c60d to your computer and use it in GitHub Desktop.
msgsvc

msgsvc

this is a very simple messge service with static file written in py

非常简单的基于静态文件的使用py写的消息服务

usage / 用法

const var / 常量

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 主服务上线

msg management / 消息管理

list msgs 列举信息

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

add msg 添加消息

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”

delete msg 删除消息

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 file 使用消息文件

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。

configure 配置

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment