一款用于飞书的流程自动化工具😊
自己的业务主要是为了汇总共享文档里的日报,在此需求上实现了几个接口,如有需求者可以自取。
生成的日报demo:
FeishuAutoTools
│ crontab.cfg // crontab配置文件
│ script.sh // 运行业务代码的脚本
├─biz // 自己的业务代码
│ │ conf.py
│ │ download_sheet_data.py // 下载飞书云文档的sheet内容到本地
│ │ log_conf.py
│ │ refresh_token.py // 刷新user_access_token和refresh_token
│ │ send_email.py // 发送邮件的模块
│ │ work_summary.py // 汇总日报
│ └─ __init__.py
├─daily_reports // 保存日报的目录
├─feishu // 飞书相关接口
│ │ authen_api.py // 身份验证相关接口
│ │ conf.py
│ │ http_utils.py // https utils
│ │ sheets_api.py // 操作sheet相关接口
│ │ token.txt // 保存user_access_token和refresh_token
│ └─ __init__.py
├─log // 日志目录
└─template // 业务用到的.xlsx和.docx
- 身份验证开发指南:参考文档
- 第一次使用时,需要构造
https://open.feishu.cn/open-apis/authen/v1/index?redirect_uri={REDIRECT_URI}&app_id={APPID}
格式的链接,在浏览器发送请求,然后完成扫码登录。登录成功后会生成登录预授权码 code,并作为参数重定向到重定向URL。 用返回的code修改./feishu/authen_api.py
里authen_code_
的值,然后运行authen_api.py
,将返回结果中的access_token和refresh_token复制出来粘贴到./feishu/token.txt
- 由于access_token不到两小时就会过期,可以配置一个定时任务保持刷新 --> 代码见
./biz/refresh_token.py
- 调用
./feishu/authen_api.py
和./feishu/sheets_api.py
中的接口即可。注意:调用需要access_token的API前,最好先刷新一下tokens避免过期 - 可以参考官网文档实现更多API: