bcmd 0.5.8__py3-none-any.whl → 0.5.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bcmd might be problematic. Click here for more details.

bcmd/tasks/__init__.py CHANGED
@@ -9,6 +9,7 @@ from . import json
9
9
  from . import lib
10
10
  from . import math
11
11
  from . import mirror
12
+ from . import pdf
12
13
  from . import project
13
14
  from . import proxy
14
15
  from . import time
bcmd/tasks/pdf.py ADDED
@@ -0,0 +1,43 @@
1
+ from pathlib import Path
2
+ from typing import Final
3
+
4
+ import fitz
5
+ import typer
6
+ from beni import bcolor, bfile, btask
7
+ from beni.bfunc import syncCall
8
+
9
+ app: Final = btask.newSubApp('PDF相关')
10
+
11
+
12
+ @app.command()
13
+ @syncCall
14
+ async def output_images(
15
+ target: Path = typer.Option(Path.cwd(), '--target', help='PDF文件路径或多个PDF文件所在的目录'),
16
+ ):
17
+ '保存 PDF 文件里面的图片'
18
+
19
+ # 列出需要检查的PDF文件
20
+ pdfFileList: list[Path] = []
21
+ if target.is_dir():
22
+ pdfFileList = list(target.glob('*.pdf'))
23
+ elif target.is_file():
24
+ pdfFileList = [target]
25
+ else:
26
+ raise ValueError("目标路径不存在")
27
+
28
+ for pdf_file in pdfFileList:
29
+ pdf_document = fitz.open(pdf_file)
30
+ output_dir = pdf_file.with_name(pdf_file.stem + '-PDF图片文件')
31
+ for page_num in range(len(pdf_document)):
32
+ page = pdf_document.load_page(page_num)
33
+ images = page.get_images(full=True)
34
+ for img_index, img in enumerate(images):
35
+ xref = img[0]
36
+ base_image = pdf_document.extract_image(xref)
37
+ image_bytes = base_image["image"]
38
+ image_ext = base_image["ext"]
39
+ image_filename = f"page{page_num + 1}_img{img_index + 1}.{image_ext}"
40
+ image_path = output_dir / image_filename
41
+ output_dir.mkdir(exist_ok=True)
42
+ bcolor.printGreen(image_path)
43
+ await bfile.writeBytes(image_path, image_bytes)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: bcmd
3
- Version: 0.5.8
3
+ Version: 0.5.9
4
4
  Summary: Commands for Beni
5
5
  Author-email: Beni Mang <benimang@126.com>
6
6
  Maintainer-email: Beni Mang <benimang@126.com>
@@ -13,6 +13,7 @@ Requires-Dist: pathspec
13
13
  Requires-Dist: pillow
14
14
  Requires-Dist: prettytable
15
15
  Requires-Dist: psutil
16
+ Requires-Dist: pymupdf
16
17
  Requires-Dist: qiniu
17
18
  Requires-Dist: twine
18
19
  Requires-Dist: typer
@@ -8,7 +8,7 @@ bcmd/resources/project/main.py,sha256=xdskz_sf05fYA1SRMFCIxDjx8SnegxTbCmHpW86ItL
8
8
  bcmd/resources/project/.vscode/launch.json,sha256=Wpghb9lW9Y1wtrjqlTbyjeejDuU8BQJmBjwsLyPRh1g,478
9
9
  bcmd/resources/project/.vscode/settings.json,sha256=G4rCroWxEHcQfsqIJ6CXRHI6VGr3WYQI3KPPjH_JANs,280
10
10
  bcmd/resources/project/.vscode/tasks.json,sha256=gouhpkrqiPz7v65Jw1Rz-BCYU3sSdmphzXIYCzVnoe0,1783
11
- bcmd/tasks/__init__.py,sha256=siqJwKgsjiIQzarBsQaucjm6VEvDr1pJDuEd7UnDXSQ,316
11
+ bcmd/tasks/__init__.py,sha256=cHy7P9387I3ouanSV12pMrKBVNZ7SoUZHsJRuf8pjMo,334
12
12
  bcmd/tasks/bin.py,sha256=B_e-HYOc2Cohk-1PbKHyKn3RhI8TAUfI2EBRoFEHiTM,2961
13
13
  bcmd/tasks/code.py,sha256=IUs_ClZuSsBk2gavlitC8mkRrQQX9rvNDgR8cFxduBA,3992
14
14
  bcmd/tasks/crypto.py,sha256=C2welnYfdI4Tc-W1cwkboGb6bk6NGWO0MRKm4Bzo_9Q,3216
@@ -19,13 +19,14 @@ bcmd/tasks/json.py,sha256=WWOyvcZPYaqQgp-Tkm-uIJschNMBKPKtZN3yXz_SC5s,635
19
19
  bcmd/tasks/lib.py,sha256=lq-PdHxhK-5Akf7k4QaIT8mBB-sCK5or5OqEFTdphIA,4567
20
20
  bcmd/tasks/math.py,sha256=xbl5UdaDMyAjiLodDPleP4Cutrk2S3NOAgurzAgOEAE,2862
21
21
  bcmd/tasks/mirror.py,sha256=nAe8NYftMKzht16MFBj7RqXwvVhR6Jh2uuAyJLh87og,1098
22
+ bcmd/tasks/pdf.py,sha256=fkHRgxqzrRxdb4_-9pL9wp2roqAHJPS_dVqAGJvRUsM,1504
22
23
  bcmd/tasks/project.py,sha256=yLYL6WNmq0mlY-hQ-SGKZ6uRjwceJxpgbP-QAo0Wk-Y,1948
23
24
  bcmd/tasks/proxy.py,sha256=xvxN5PClUnc5LQpmq2Wug7_LUVpJboMWLXBvL9lX7EM,1552
24
25
  bcmd/tasks/time.py,sha256=ZiqA1jdgl-TBtFSOxxP51nwv4g9iZItmkFKpf9MKelk,2453
25
26
  bcmd/tasks/upgrade.py,sha256=ZiyecgVbnnoTU_LAsd78CIKA4ioc9so9pXpAM76b_0M,447
26
27
  bcmd/tasks/venv.py,sha256=a7ZDyagUPQvCAXx3cZJIqJt0p1Iy5u5qmmj8iRbDQZE,7673
27
- bcmd-0.5.8.dist-info/METADATA,sha256=dxjitrNJe9aAj4AoZWfaXZQPfFbagkj4MzvGjFsgp9E,475
28
- bcmd-0.5.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
- bcmd-0.5.8.dist-info/entry_points.txt,sha256=rHJrP6KEQpB-YaQqDFzEL2v88r03rxSfnzAayRvAqHU,39
30
- bcmd-0.5.8.dist-info/top_level.txt,sha256=-KrvhhtBcYsm4XhcjQvEcFbBB3VXeep7d3NIfDTrXKQ,5
31
- bcmd-0.5.8.dist-info/RECORD,,
28
+ bcmd-0.5.9.dist-info/METADATA,sha256=cvbOTNQeImLrBxhbBDSwN27j4HjCz1wWTNOBNCBE420,499
29
+ bcmd-0.5.9.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
30
+ bcmd-0.5.9.dist-info/entry_points.txt,sha256=rHJrP6KEQpB-YaQqDFzEL2v88r03rxSfnzAayRvAqHU,39
31
+ bcmd-0.5.9.dist-info/top_level.txt,sha256=-KrvhhtBcYsm4XhcjQvEcFbBB3VXeep7d3NIfDTrXKQ,5
32
+ bcmd-0.5.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5