Skip to content

Commit 781e65a

Browse files
committed
add pyinstaller and github action
1 parent 7dfd344 commit 781e65a

File tree

7 files changed

+118
-9
lines changed

7 files changed

+118
-9
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Build Windows Executable
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 触发工作流的分支
7+
8+
jobs:
9+
build:
10+
runs-on: windows-latest # 使用 Windows 环境
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3 # 拉取代码
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4 # 安装 Python
17+
with:
18+
python-version: '3.13' # 指定 Python 版本
19+
20+
- name: Install Poetry
21+
run: |
22+
pip install poetry # 安装 Poetry
23+
24+
- name: Install dependencies
25+
run: |
26+
poetry install # 使用 Poetry 安装依赖
27+
28+
- name: Build executable
29+
run: |
30+
poetry run pyinstaller --onefile --name upload_images upload_all_images_in_markdown/main.py # 使用 Poetry 运行 PyInstaller 打包程序
31+
32+
- name: Upload artifact
33+
uses: actions/upload-artifact@v3 # 上传生成的 .exe 文件
34+
with:
35+
name: upload-images.exe
36+
path: dist/upload-images.exe

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# ...existing code...
22

33
# Ignore configuration file with sensitive information
4-
# config.json
4+
/config.json
5+
56
log/
67
**/__pycache__/
7-
config.json
8+
build/

README.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,27 @@ Convert image links in all Markdown files within a folder to online Markdown lin
3232

3333
想把有道云笔记里的几千篇笔记迁移到 Obsidian 中,感谢[youdaonote-pull](https://github.com/DeppWang/youdaonote-pull)提供的有道云笔记的全量导出功能,很快把所有笔记导出到了本地文件夹,但是由于几千张笔记中的图片也保留在本地,不方便移动端使用,所以想把图片上传到图床,使用markdown链接到笔记里。于是自己写了个批量转换并上传图片的程序。
3434

35+
## 安装包运行
36+
37+
1. 下载安装包
38+
2. 解压
39+
3. 配置 `config.json` 文件
40+
- 配置 `vault_directory` 为笔记所在的文件夹路径
41+
- 配置 `upload_url` 为 PicList/PicGo 服务的 URL
42+
- 配置 `base_url` 为图床的 URL
43+
- 配置 `cleanup` 为是否清理本地图片
44+
4. 运行
45+
- Windows 用户双击 `upload-images.exe` 运行。
46+
- macOS 在terminal中输入 `./upload-images` 运行。
47+
48+
49+
## 使用Python运行或开发
3550
### 安装
3651

52+
环境准备:python、poetry
53+
54+
直接运行poetry install即可完成依赖项和环境安装
55+
3756
```bash
3857
poetry install
3958
```
@@ -45,15 +64,17 @@ poetry install
4564
#### 使用命令行参数
4665

4766
```bash
48-
poetry run upload-all-images-in-markdown <vault_directory> --upload_url <UPLOAD_URL> --cleanup
67+
python upload_all_images_in_markdown/main.py <vault_directory> --upload_url <UPLOAD_URL> --cleanup
4968
```
5069

5170
#### 使用配置文件
5271

5372
```bash
54-
poetry run upload-all-images-in-markdown --config config.json
73+
python upload_all_images_in_markdown/main.py --config config.json
5574
```
5675

76+
不指定配置文件名时,会使用默认配置文件名`config.json`
77+
5778
#### 结合使用
5879

5980
命令行参数会覆盖配置文件中的值。
@@ -89,9 +110,7 @@ poetry run pytest
89110
---
90111

91112
## English Documentation
92-
93113
### Table of Contents
94-
95114
- [English Documentation](#english-documentation)
96115
- [Table of Contents](#table-of-contents)
97116
- [Introduction](#introduction)
@@ -119,6 +138,10 @@ I wanted to migrate thousands of notes from Youdao Cloud Notes to Obsidian. Than
119138

120139
### Installation
121140

141+
Prerequisites: Python, Poetry
142+
143+
Run the following command to install dependencies and set up the environment:
144+
122145
```bash
123146
poetry install
124147
```
@@ -130,21 +153,23 @@ You can run the script with command-line arguments or specify a configuration fi
130153
#### Using Command-Line Arguments
131154

132155
```bash
133-
poetry run upload-all-images-in-markdown <vault_directory> --upload_url <UPLOAD_URL> --cleanup
156+
python upload_all_images_in_markdown/main.py <vault_directory> --upload_url <UPLOAD_URL> --cleanup
134157
```
135158

136159
#### Using a Configuration File
137160

138161
```bash
139-
poetry run upload-all-images-in-markdown --config config.json
162+
python upload_all_images_in_markdown/main.py --config config.json
140163
```
141164

165+
If no configuration file is specified, the default `config.json` will be used.
166+
142167
#### Combining Both
143168

144169
Command-line arguments will override the values in the configuration file.
145170

146171
```bash
147-
poetry run upload-all-images-in-markdown --config config.json --upload_url <UPLOAD_URL>
172+
python upload_all_images_in_markdown/main.py --config config.json --upload_url <UPLOAD_URL>
148173
```
149174

150175
### Configuration

dist/config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"vault_directory": "/path/to/vault-directory",
3+
"base_url": "https://example.com/",
4+
"upload_url": "http://127.0.0.1:36677/upload",
5+
"cleanup": false,
6+
"test_vault_dir": "/path/to/test-notes",
7+
"test_upload_url": "http://example.com/upload"
8+
}

dist/upload_images

8.07 MB
Binary file not shown.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ requests = "^2.26.0"
1111

1212
[tool.poetry.dev-dependencies]
1313
pytest = "^6.2"
14+
pyinstaller = "^6.0.0"
1415

1516
[tool.poetry.scripts]
1617
upload-all-images-in-markdown = "upload_all_images_in_markdown:main"

upload_images.spec

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
a = Analysis(
5+
['upload_all_images_in_markdown/main.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[],
9+
hiddenimports=[],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
noarchive=False,
15+
optimize=0,
16+
)
17+
pyz = PYZ(a.pure)
18+
19+
exe = EXE(
20+
pyz,
21+
a.scripts,
22+
a.binaries,
23+
a.datas,
24+
[],
25+
name='upload_images',
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=True,
30+
upx_exclude=[],
31+
runtime_tmpdir=None,
32+
console=True,
33+
disable_windowed_traceback=False,
34+
argv_emulation=False,
35+
target_arch=None,
36+
codesign_identity=None,
37+
entitlements_file=None,
38+
)

0 commit comments

Comments
 (0)