Send_picture_automatically/send_filemsg.py
teddy 7233700539 feat: 重构定时任务系统并增强配置管理
- 将硬编码的时间配置改为从CONFIG读取
- 支持多接收人配置,修改open_id为数组类型
- 增加发送时间等待功能,确保消息在指定时间发送
- 改进停止定时任务的进程查找逻辑
- 更新配置项,增加checking_time、sending_time和message字段
2025-06-26 17:24:50 +08:00

42 lines
1.3 KiB
Python

import json
import lark_oapi as lark
from lark_oapi.api.im.v1 import *
from config import CONFIG
def main():
Local_openid = CONFIG['open_id']
client = lark.Client.builder() \
.app_id(CONFIG['app_id']) \
.app_secret(CONFIG['app_secret']) \
.log_level(lark.LogLevel.DEBUG) \
.build()
for local_openid in Local_openid:
# 构造请求对象
request: CreateMessageRequest = CreateMessageRequest.builder() \
.receive_id_type("open_id") \
.request_body(CreateMessageRequestBody.builder()
.receive_id(local_openid)
.msg_type("text")
.content("{\"text\":\"未找到指定图片,请手动发送\"}")
.build()) \
.build()
# 发起请求
response: CreateMessageResponse = client.im.v1.message.create(request)
# 处理失败返回
if not response.success():
lark.logger.error(
f"client.im.v1.message.create failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}, resp: \n{json.dumps(json.loads(response.raw.content), indent=4, ensure_ascii=False)}")
return
# 处理业务结果
lark.logger.info(lark.JSON.marshal(response.data, indent=4))
if __name__ == "__main__":
main()