init
This commit is contained in:
commit
0407d02129
19
.vscode/launch.json
vendored
Normal file
19
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Python: 当前文件",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"args": [
|
||||
"${workspaceFolder}/test.md"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
45
remove.py
Normal file
45
remove.py
Normal file
@ -0,0 +1,45 @@
|
||||
# auto remove unuse img
|
||||
from pathlib import Path
|
||||
import argparse
|
||||
import chardet
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# get opt
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("file", help="specifi the markdown file", type=str)
|
||||
parser.add_argument("-a", "--assets", help="specifi the img dir", type=str)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.assets:
|
||||
img_dir = Path(args.assets)
|
||||
else:
|
||||
img_dir = Path(args.file).with_suffix('.assets')
|
||||
|
||||
with open(args.file, 'rb') as file:
|
||||
result = chardet.detect(file.read())
|
||||
print("{} encoding is {}, confidence: {}".format(args.file, result['encoding'], result['confidence']))
|
||||
with open(args.file, 'r', encoding=result['encoding']) as file:
|
||||
content = file.read()
|
||||
|
||||
img_list = list(img_dir.glob('**/*'))
|
||||
unuse_img_list = []
|
||||
for file_name in img_list:
|
||||
img_name = Path(file_name).name
|
||||
if img_name not in content:
|
||||
print("img:{}".format(img_name))
|
||||
unuse_img_list.append(file_name)
|
||||
|
||||
if len(unuse_img_list) == 0:
|
||||
print("not find unuse img file")
|
||||
else:
|
||||
print("find {} unuse img files:".format(len(unuse_img_list)))
|
||||
for file_name in unuse_img_list:
|
||||
print("{}".format(file_name))
|
||||
usr_input = input("would you want to delete them?(y or n):")
|
||||
if usr_input == "y":
|
||||
for file_name in unuse_img_list:
|
||||
print("delete {}".format(file_name))
|
||||
Path(file_name).unlink()
|
||||
else:
|
||||
print("unused img will not remove!")
|
BIN
test.assets/img.png
Normal file
BIN
test.assets/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 174 KiB |
BIN
test.assets/写周报了.png
Normal file
BIN
test.assets/写周报了.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
test.assets/萌萌的伊雷娜.jpg
Normal file
BIN
test.assets/萌萌的伊雷娜.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 504 KiB |
Loading…
x
Reference in New Issue
Block a user