Enhance announcement storage functionality by adding a method to save all announcements by source, retaining the latest 100 per source. Update related logging and comments for clarity. Adjusted the main script to utilize the new storage method and log the saving process. Updated the markdown file timestamp.

This commit is contained in:
2026-01-08 09:31:47 +08:00
parent 28c57a040a
commit 317dbf3c58
37 changed files with 3065 additions and 10 deletions
@@ -0,0 +1,223 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File UserTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
import sys
sys.path.append("../src/")
import random
from CorpApi import *
from TestConf import *
## test
api = CorpApi(TestConf['CORP_ID'], TestConf['APP_SECRET'])
chatid = "test210";
try :
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_CREATE'],
{
'name' : 'appchat_test',
'owner' : 'ZhuBiaoYi',
'userlist' : ['LiShuang', 'ZhuShengBen', 'LinJianEn', 'ZhuBiaoYi', 'XuBin', 'yangpeiyi', 'HaLuoTeQu', 'lucky', 'raindong', 'simon', 'Wang', 'ZhaoDong', 'DengLinSheng', 'Li'],
'chatid' : chatid,
})
print response
chatid = response['chatid']
except ApiException as e :
print e.errCode, e.errMsg
try :
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_UPDATE'],
{
'chatid' : chatid,
'name' : 'appchat_test_new_name',
'owner' : 'ZhuShengBen',
'add_user_list' : ['huqiqi', 'Wang']
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_UPDATE'],
{
'chatid' : chatid,
'name' : '应用发消息测试',
'owner' : 'ZhuBiaoYi',
'del_user_list' : 'huqiqi',
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'msgtype' : 'text',
'text' : {'content':'我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党我是文本消息热爱祖国热爱人民热爱中国共产党'},
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'msgtype' : 'image',
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'image' : {
'media_id':'3A9Jo9CHit_5UTfOVE38_067dUJQlLs30mOa9FC0a4jEGeoQgpLCZgc7rEza6TbfB',
},
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'msgtype' : 'file',
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'file' : {
'media_id':'35L7MmcpGdyFfqjbGhbECCkGcaNsUajaPQifGLJq_H5E',
},
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'msgtype' : 'voice',
'voice' : {
'media_id':'3x1yb34061fDXjyUXy2rWNd-a-hWe-l8eTw2VKyh3bDQ',
},
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'msgtype' : 'video',
'video' : {
'media_id':'3neA1ypnC3k5QnAZqvyVvCesFYUrXietU5F-Ipnj6ZobiD-PuFlXngzPplWXibw9r',
},
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'msgtype' : 'news',
"news" : {
"articles" : [
{
"title" : "图文消息",
"description" : "今年中秋节公司有豪礼相送",
"url" : "URL",
"picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png",
"btntxt":"更多",
},
{
"title" : "图文消息",
"description" : "今年中秋节公司有豪礼相送",
"url" : "URL",
"picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png",
"btntxt":"更多",
},
{
"title" : "图文消息",
"description" : "今年中秋节公司有豪礼相送",
"url" : "URL",
"picurl" : "http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png",
"btntxt":"更多",
},
]},
'safe' : 1,
},
)
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
'msgtype' : 'textcard',
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'textcard' : {
'title':'我是文本卡片消息',
'description' : 'aaaaaaa',
'url' : 'www.qq.com',
'btntxt' : '更多',
},
'safe' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['APP_CHAT_SEND'],
{
'chatid':chatid,
"msgtype" : "mpnews",
"mpnews": {
"articles" : [
{
"title" : "图文消息(mpnews)",
"thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc",
"author" : "author",
"content" : "content",
"digest" : "我是图文"
},
{
"title" : "图文消息(mpnews)",
"thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc",
"author" : "author",
"content" : "content",
"digest" : "我是图文"
},
{
"title" : "图文消息(mpnews)",
"thumb_media_id" : "3uFTZs4MRTr-OwUArqaoXPyqtuedcwCUW1x4sgKcOeQc",
"author" : "author",
"content" : "content",
"digest" : "我是图文"
},
]
},
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'safe' : 1,
})
print response
except ApiException as e :
print e.errCode, e.errMsg
@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File UserTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
import sys
sys.path.append("../src/")
import random
from CorpApi import *
from TestConf import *
## test
api = CorpApi(TestConf['CORP_ID'], TestConf['APP_SECRET'])
try :
##
response = api.httpCall(
CORP_API_TYPE['MESSAGE_SEND'],
{
"touser": "ZhuShengBen",
"agentid": 1000002,
'msgtype' : 'text',
'climsgid' : 'climsgidclimsgid_%f' % (random.random()),
'text' : {
'content':'方法论',
},
'safe' : 0,
})
print response
except ApiException as e :
print e.errCode, e.errMsg
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File UserTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
import sys
sys.path.append("../src/")
import random
from CorpApi import *
from TestConf import *
## test
api = CorpApi(TestConf['CORP_ID'], TestConf['APP_SECRET'])
try :
##
response = api.httpCall(
CORP_API_TYPE['MINIPROGRAM_CODE_TO_SESSION_KEY'],
{
"js_code" : "sVqtL3itg0L30LTGJtZ_isKC0efG5FqGw470fVp8Dpw",
"grant_type" : "authorization_code"
})
print response
except ApiException as e :
print e.errCode, e.errMsg
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File ServiceCorpTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
import sys
sys.path.append("../src/")
from ServiceCorpApi import *
from TestConf import *
## 第三方服务商接口的使用方法
api = ServiceCorpApi(
"SUITE_ID",
"SUITE_SECRET",
"SUITE_TICKET"
);
try :
pre_auth_code = api.httpCall(SERVICE_CORP_API_TYPE['GET_PRE_AUTH_CODE']).get('pre_auth_code')
print pre_auth_code
except ApiException as e :
print e.errCode, e.errMsg
## 第三方服务商使用永久授权码调用企业接口的方法
api = ServiceCorpApi(
"SUITE_ID",
"SUITE_SECRET",
"SUITE_TICKET",
'AUTH_CORPID',
'PERMANENT_CODE'
);
try :
response = api.httpCall(
CORP_API_TYPE['USER_GET'],
{
'userid' : 'zhangsan',
})
print response
except ApiException as e :
print e.errCode, e.errMsg
@@ -0,0 +1,30 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File ServiceProviderTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-26
#
#
import sys
sys.path.append("../src/")
from ServiceProviderApi import *
from TestConf import *
api = ServiceProviderApi('CORPID', 'PROVIDER_SECRET')
try :
response = api.httpCall(
SERVICE_PROVIDER_API_TYPE['GET_LOGIN_INFO'],
{
'auth_code' : 'XXXXXXX',
})
print response
except ApiException as e :
print e.errCode, e.errMsg
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File conf.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
# 请将下面参数改为自己的企业相关参数再进行测试
TestConf = {
# 企业的id,在管理端->"我的企业" 可以看到
"CORP_ID" : "ww55ca070cb9b7eb22",
# "通讯录同步"应用的secret, 开启api接口同步后,可以在管理端->"通讯录同步"看到
"CONTACT_SYNC_SECRET" : "ktmzrVIlUH0UW63zi7-JyzsgTL9NfwUhHde6or6zwQY",
# 某个自建应用的id及secret, 在管理端 -> 企业应用 -> 自建应用, 点进相应应用可以看到
"APP_ID" : 1000002,
"APP_SECRET" : "v1Z2KSw2WqPFECAwn2R0a1dFsanVF5sE4IE6X5ogveQ",
# 打卡应用的 id 及secrete 在管理端 -> 企业应用 -> 基础应用 -> 打卡,
# 点进去,有个"api"按钮,点开后,会看到
"CHECKIN_APP_ID" : 3010011,
"CHECKIN_APP_SECRET" : "3Qz2OGPvE1Eb6WKpEDfczvyQjL5Lr1CjrDTKn0RHdLE",
# 审批应用的 id 及secrete 在管理端 -> 企业应用 -> 基础应用 -> 审批,
# 点进去,有个"api"按钮,点开后,会看到
"APPROVAL_APP_ID" : 3010040,
"APPROVAL_APP_SECRET" : "1vrlwItWpz_5Qkud55aImQPCvpzi51H3F2j-1OQzhYE",
}
@@ -0,0 +1,63 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
##
# Copyright (C) 2018 All rights reserved.
#
# @File UserTest.py
# @Brief
# @Author abelzhu, abelzhu@tencent.com
# @Version 1.0
# @Date 2018-02-24
#
#
import sys
sys.path.append("../src/")
from CorpApi import *
from TestConf import *
## test
api = CorpApi(TestConf['CORP_ID'], TestConf['CONTACT_SYNC_SECRET'])
try :
##
response = api.httpCall(
CORP_API_TYPE['USER_CREATE'],
{
'userid' : 'zhangsan',
'name' : 'zhangsanfeng',
'mobile' : '131488888888',
'email' : 'zhangsan@ipp.cas.cn',
'department' : 1,
})
print response
##
response = api.httpCall(
CORP_API_TYPE['USER_GET'],
{
'userid' : 'zhangsan',
})
print response
##
response = api.httpCall(
CORP_API_TYPE['USER_DELETE'],
{
'userid' : 'zhangsan',
})
print response
except ApiException as e :
print e.errCode, e.errMsg
##
response = api.httpCall(
CORP_API_TYPE['USER_DELETE'],
{
'userid' : 'zhangsan',
})
print response