nt25 0.1.3__tar.gz → 0.1.4__tar.gz

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.
@@ -18,3 +18,8 @@ ds/
18
18
 
19
19
  # output
20
20
  output/
21
+
22
+ # others
23
+ *.jpg
24
+ *.png
25
+
@@ -1,11 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nt25
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Neo's Tools of Python
5
5
  Requires-Python: >=3.10
6
+ Requires-Dist: exif>=1.6.1
6
7
  Requires-Dist: matplotlib>=3.10.6
7
8
  Requires-Dist: openpyxl>=3.1.5
8
9
  Requires-Dist: pandas>=2.3.2
10
+ Requires-Dist: pyinstaller>=6.15.0
9
11
  Requires-Dist: scikit-learn>=1.7.1
10
12
  Requires-Dist: sympy>=1.14.0
11
13
  Description-Content-Type: text/markdown
@@ -14,11 +16,12 @@ Description-Content-Type: text/markdown
14
16
 
15
17
  Neo's Tools of Python in 2025
16
18
 
17
- ## plans
19
+ ## TODO
18
20
 
19
21
  - [x] fio
20
22
  - [x] calc
21
23
  - [x] draw
24
+ - [x] et: EXIF tools
22
25
  - [ ] mysql
23
26
  - [ ] redis
24
27
  - [ ] maptrans
@@ -28,7 +31,10 @@ Neo's Tools of Python in 2025
28
31
 
29
32
  ```sh
30
33
  uv init
31
- uv run ntpy
34
+ # fio, calc, draw basic demo
35
+ uv run nt25
36
+ # et
37
+ uv run et
32
38
  ```
33
39
 
34
40
  ## fun
@@ -2,11 +2,12 @@
2
2
 
3
3
  Neo's Tools of Python in 2025
4
4
 
5
- ## plans
5
+ ## TODO
6
6
 
7
7
  - [x] fio
8
8
  - [x] calc
9
9
  - [x] draw
10
+ - [x] et: EXIF tools
10
11
  - [ ] mysql
11
12
  - [ ] redis
12
13
  - [ ] maptrans
@@ -16,7 +17,10 @@ Neo's Tools of Python in 2025
16
17
 
17
18
  ```sh
18
19
  uv init
19
- uv run ntpy
20
+ # fio, calc, draw basic demo
21
+ uv run nt25
22
+ # et
23
+ uv run et
20
24
  ```
21
25
 
22
26
  ## fun
@@ -1,20 +1,26 @@
1
1
  [project]
2
2
  name = "nt25"
3
- version = "0.1.3"
3
+ version = "0.1.4"
4
4
  description = "Neo's Tools of Python"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
7
7
  dependencies = [
8
+ "exif>=1.6.1",
8
9
  "matplotlib>=3.10.6",
9
10
  "openpyxl>=3.1.5",
10
11
  "pandas>=2.3.2",
12
+ "pyinstaller>=6.15.0",
11
13
  "scikit-learn>=1.7.1",
12
14
  "sympy>=1.14.0",
13
15
  ]
14
16
 
15
17
  [project.scripts]
16
18
  nt25 = "nt25.main:main"
19
+ et = "nt25.lib.et:main"
17
20
 
18
21
  [build-system]
19
22
  requires = ["hatchling"]
20
23
  build-backend = "hatchling.build"
24
+
25
+ [tool.hatch.build.targets.sdist]
26
+ only-include = ["src", "tests"]
@@ -0,0 +1,142 @@
1
+ import time
2
+ import json
3
+ import argparse
4
+
5
+ from datetime import UTC, datetime, timedelta, timezone
6
+ from exif import Image
7
+
8
+ VERSION = "0.1.1"
9
+
10
+ EPOCH = datetime.fromtimestamp(0, UTC)
11
+ IGNORE = ['orientation', 'maker_note', '_interoperability_ifd_Pointer',
12
+ 'components_configuration', 'scene_type', 'flashpix_version',
13
+ 'gps_processing_method',]
14
+
15
+
16
+ def dms2dec(dms: tuple):
17
+ d, m, s = dms
18
+ return d + m/60 + s/3600
19
+
20
+
21
+ def dtFormatter(str):
22
+ return datetime.strptime(str, '%Y:%m:%d %H:%M:%S')
23
+
24
+
25
+ def dt2str(dt):
26
+ return None if dt is None else dt.strftime('%Y-%m-%d %H:%M:%S')
27
+
28
+
29
+ def gpsDt2Dt(date, time, offset=8):
30
+ d = dtFormatter(f"{date} {int(time[0])}:{int(time[1])}:{int(time[2])}")
31
+ utc = d.replace(tzinfo=timezone.utc)
32
+ return utc.astimezone(timezone(timedelta(hours=offset)))
33
+
34
+
35
+ def tryGet(img, key, default):
36
+ value = default
37
+
38
+ try:
39
+ value = img[key]
40
+ except Exception:
41
+ pass
42
+
43
+ return value
44
+
45
+
46
+ def dumpExif(file):
47
+ result = {}
48
+ with open(file, 'rb') as f:
49
+ img = Image(f)
50
+ for key in img.get_all():
51
+ try:
52
+ result[key] = str(img[key])
53
+ except Exception:
54
+ pass
55
+
56
+ return result
57
+
58
+
59
+ def parseExif(file):
60
+ with open(file, 'rb') as f:
61
+ try:
62
+ img = Image(f)
63
+ except Exception:
64
+ return {}
65
+
66
+ width = tryGet(img, 'pixel_x_dimension', -1)
67
+ height = tryGet(img, 'pixel_y_dimension', -1)
68
+
69
+ if width < 0:
70
+ width = tryGet(img, 'image_width', -1)
71
+ height = tryGet(img, 'image_height', -1)
72
+
73
+ create = tryGet(img, 'datetime_original', None)
74
+ modify = tryGet(img, 'datetime', None)
75
+
76
+ # da = []
77
+ # for d in (d1, d2, d3):
78
+ # if d is not None:
79
+ # print(d)
80
+ # da.append(dtFormatter(d))
81
+ # dt = None if len(da) == 0 else max(da)
82
+
83
+ createDt = None if create is None else dtFormatter(create)
84
+ modifyDt = None if modify is None else dtFormatter(modify)
85
+
86
+ latitude = tryGet(img, 'gps_latitude', None)
87
+ latitude = None if latitude is None else dms2dec(latitude)
88
+
89
+ longitude = tryGet(img, 'gps_longitude', None)
90
+ longitude = None if longitude is None else dms2dec(longitude)
91
+
92
+ gpsDatetime = None
93
+ gd = tryGet(img, 'gps_datestamp', None)
94
+ gt = tryGet(img, 'gps_timestamp', None)
95
+
96
+ if gd and gt:
97
+ offset = int(time.localtime().tm_gmtoff / 3600)
98
+ gpsDatetime = gpsDt2Dt(gd, gt, offset=offset)
99
+
100
+ ts = -1 if createDt is None else int(createDt.timestamp())
101
+ mTs = -1 if modifyDt is None else int(modifyDt.timestamp())
102
+ gpsTs = -1 if gpsDatetime is None else int(gpsDatetime.timestamp())
103
+ offset = max(mTs, gpsTs) - ts
104
+ offsetDelta = datetime.fromtimestamp(offset, UTC) - EPOCH
105
+
106
+ return {
107
+ "width": width,
108
+ "height": height,
109
+ "latitude": latitude,
110
+ "longitude": longitude,
111
+ "datetime.create": dt2str(createDt),
112
+ "datetime.modify": dt2str(modifyDt),
113
+ "datetime.gps": dt2str(gpsDatetime),
114
+ "ts": ts,
115
+ "offset": offset,
116
+ "offset.delta": str(offsetDelta),
117
+ }
118
+
119
+
120
+ def main():
121
+ parser = argparse.ArgumentParser(description="EXIF tool")
122
+ parser.add_argument('-v', '--version',
123
+ help='echo version', action='store_true')
124
+ parser.add_argument('-d', '--dump', help='dump meta', action='store_true')
125
+ parser.add_argument('-f', '--file', type=str, help='image file')
126
+
127
+ args = parser.parse_args()
128
+
129
+ if args.version:
130
+ print(f"et: {VERSION}")
131
+ return
132
+
133
+ if args.file is None:
134
+ print("usage: et [-h] [-v] [-d] [-f FILE]")
135
+ return
136
+
137
+ r = dumpExif(args.file) if args.dump else parseExif(args.file)
138
+ print(json.dumps(r, indent=2, sort_keys=False))
139
+
140
+
141
+ if __name__ == "__main__":
142
+ main()
@@ -0,0 +1,8 @@
1
+ #!env bash
2
+ uvx pyinstaller \
3
+ --hidden-import=matplotlib \
4
+ --hidden-import=openpyxl \
5
+ --hidden-import=pandas \
6
+ --hidden-import=scikit-learn \
7
+ --hidden-import=sympy \
8
+ ./src/nt25/main.py
nt25-0.1.4/tests/qr.py ADDED
@@ -0,0 +1,60 @@
1
+ # "pyzbar>=0.1.9",
2
+ # "qrcode[pil]>=8.2",
3
+
4
+ import qrcode
5
+ import qrcode.constants
6
+
7
+ from pyzbar.pyzbar import decode
8
+ from PIL import Image, ImageOps
9
+
10
+
11
+ def make_qr(data: str, file: str, mask=6, size=10, border=4,
12
+ ecc=qrcode.constants.ERROR_CORRECT_L, fg="black", bg="white",):
13
+ qr = qrcode.QRCode(
14
+ version=None,
15
+ mask_pattern=mask,
16
+ error_correction=ecc,
17
+ box_size=size,
18
+ border=border,)
19
+
20
+ qr.add_data(data)
21
+ qr.make(fit=True)
22
+
23
+ img = qr.make_image(fill_color=fg, back_color=bg)
24
+ img.save(file)
25
+ print(f"{file}")
26
+
27
+
28
+ def read_qr(file: str) -> list[str]:
29
+ objs = decode(Image.open(file))
30
+ print(objs)
31
+ texts = [o.data.decode("utf-8") for o in objs if o.type == "QRCODE"]
32
+ return texts
33
+
34
+
35
+ def magic(file, output):
36
+ img = Image.open(file)
37
+ img = ImageOps.mirror(img)
38
+ img = img.rotate(90, expand=True)
39
+ # ffmpeg -i input.png -filter_complex "[0:v]vflip,rotate=PI/2" -c:v png output.png
40
+ img.save(output)
41
+
42
+
43
+ if __name__ == "__main__":
44
+ url = "http://grcx.jnhrss.jinan.jnaw.top:8090/vp/mainFrameQrd.jsp?entryid=viewYjByYzm&yzm=JNRS39c9817bbebac8av"
45
+ target = "o.png"
46
+
47
+ make_qr(url, target+".png")
48
+ read_qr("qa.png")
49
+ read_qr("na.jpg")
50
+ read_qr("o.png.png")
51
+
52
+ # read_qr(target+".png")
53
+
54
+ # magic(target+".png", target)
55
+ # read_qr(target)
56
+
57
+ # refer = read_qr('./tests/t.png')
58
+ # for i in range(8):
59
+ # r = read_qr(f"./tests/qrcode_mask_{i}.jpg")
60
+ # print(r == refer)
nt25-0.1.3/.editorconfig DELETED
@@ -1,10 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- insert_final_newline = true
7
- trim_trailing_whitespace = true
8
- end_of_line = lf
9
- charset = utf-8
10
- max_line_length = 88
nt25-0.1.3/.flake8 DELETED
@@ -1,2 +0,0 @@
1
- [flake8]
2
- indent-size = 2
@@ -1,29 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- push:
5
- tags: ["*"]
6
-
7
- jobs:
8
- pypi-publish:
9
- runs-on: ubuntu-latest
10
-
11
- permissions:
12
- id-token: write
13
-
14
- environment:
15
- name: publish
16
- url: https://pypi.org/p/nt25
17
-
18
- steps:
19
- - name: Checkout
20
- uses: actions/checkout@v4
21
-
22
- - name: Setup
23
- uses: astral-sh/setup-uv@v6
24
-
25
- - name: Build
26
- run: uv build
27
-
28
- - name: Publish
29
- uses: pypa/gh-action-pypi-publish@release/v1
@@ -1 +0,0 @@
1
- 3.13
@@ -1,3 +0,0 @@
1
- {
2
- "cSpell.words": ["bfunc"]
3
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes