项目地址
DefensiveSniper/Amateur
此项目仅为蒟蒻本人学习、接触知识而随手创建的,目前没有任何实际意义,也没有深入继续探索。
flask+electron
打包flask
pyinstaller --onefile --noconsole --name=flask_server --add-data "templates;templates" --add-data "static;static" --add-data "func;func" --collect-binaries azure.cognitiveservices.speech flask_server.py
解释:
--onefile
:打包成一个独立的文件--noconsole
:隐藏终端窗口,避免黑框弹出--add-data "templates;templates"
:添加数据,防止找不到关联文件--name=flask_server
:生成flask_server.exe
成功后,dist/
目录下会生成 flask_server.exe
打包 Electron
安装 Electron 及构建工具
npm install
npm install -g electron electron-builder wait-on concurrently
修改 package.json
在 package.json
里,添加:
"build": {
"appId": "com.yourapp.id",
"productName": "AmateurApp",
"win": {
"target": "nsis",
"icon": "static/images/logo.ico"
}
}
执行打包,onlyWindows
electron-builder --win --x64
ps:记得改版本号
运行
npm run start
ps:记得在main.js中变动调试代码
笔记
前端FormData
内容的获取
表单用 FormData
时,只会收集带有 name
属性的表单项,和 id
没关系。
<form id="douyin-download-form" style="display: flex; flex-direction: column; gap: 22px;">
<label>
<span style="font-weight:500;">sec_user_id:</span>
<input type="text" name="sec_user_id" id="sec_user_id" class="input-field" placeholder="请输入sec_user_id" required>
</label>
</form>
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
若<input>
中的name
属性缺失,那么data
的数据则为空
eventlet
猴子补丁
保证在monkey_patch
之后才import
其它内容,否则requests、threading、socketio、Flask
内部依赖的socket
等都无法被eventlet
控制。
猴子补丁一定要在最最最最前面打,不然所有异步、websocket、定时操作全都可能崩溃。
import eventlet
eventlet.monkey_patch()
import .....
request请求返回的三种结构
response.text
是 字符串,拿到的是网页或接口响应的“文本内容”。
response.json()
是直接解析成 Python 的字典/列表(前提是返回内容本身就是标准 JSON 格式)。
response.content
是 二进制内容,比如图片、文件等。
日志
2025.2.6 AmateurApp1.0.0
2025.2.6 AmateurApp1.0.1 修复了应用伪关闭的问题
2025.2.7 AmateurApp1.1.0 添加了AI交流,支持DeepSeek和OPENAI的多种模型
2025.2.8 AmateurApp1.1.2 在ai交流页面添加“新聊天”按钮,优化“配置”设置
2025.2.16 AmateurApp1.1.3 添加了AI交流上下文
2025.7.7 AmateurApp1.1.4 添加了聊天记录功能