fix: add pathlib and PYTHONPATH for rename camera script
This commit is contained in:
1 parent
6e9e150253
commit
c6aa1ac6fb
2 files changed
+9
-6
No files matched your search
@@ -6,7 +6,8 @@ import sys
|
|||||||
from PIL import Image, ExifTags
|
from PIL import Image, ExifTags
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
from serverLibary import safe_rename
|
from serverlibary import safe_rename
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
# Folder to scan
|
# Folder to scan
|
||||||
folder_path = '.'
|
folder_path = '.'
|
||||||
@@ -136,6 +137,7 @@ def get_manufacturer(file_path):
|
|||||||
return author_no_spaces
|
return author_no_spaces
|
||||||
|
|
||||||
def process_images(folder):
|
def process_images(folder):
|
||||||
|
folder = Path(folder)
|
||||||
for fname in os.listdir(folder):
|
for fname in os.listdir(folder):
|
||||||
fpath = os.path.join(folder, fname)
|
fpath = os.path.join(folder, fname)
|
||||||
|
|
||||||
@@ -181,7 +183,7 @@ def process_images(folder):
|
|||||||
else:
|
else:
|
||||||
basename, _ = os.path.splitext(fname)
|
basename, _ = os.path.splitext(fname)
|
||||||
new_fname = f"{basename}{videoManufacturer}{ext}"
|
new_fname = f"{basename}{videoManufacturer}{ext}"
|
||||||
safe_rename(fpath, os.path.join(folder, new_fname))
|
safe_rename(Path(fpath),folder / new_fname)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"[OK] {fname} already correctly named.")
|
print(f"[OK] {fname} already correctly named.")
|
||||||
@@ -196,7 +198,7 @@ def process_images(folder):
|
|||||||
timestamp_str = '_'.join(parts[:2]) if len(parts) >= 2 else parts[0]
|
timestamp_str = '_'.join(parts[:2]) if len(parts) >= 2 else parts[0]
|
||||||
dt = datetime.datetime.strptime(timestamp_str, fmt)
|
dt = datetime.datetime.strptime(timestamp_str, fmt)
|
||||||
new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
|
new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
|
||||||
safe_rename(fpath, os.path.join(folder, new_fname))
|
safe_rename(Path(fpath),folder / new_fname)
|
||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -209,7 +211,7 @@ def process_images(folder):
|
|||||||
dt = get_exif_creation_datetime(fpath)
|
dt = get_exif_creation_datetime(fpath)
|
||||||
if dt:
|
if dt:
|
||||||
new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
|
new_fname = f"{file_prefix}_{dt.strftime('%Y%m%d_%H%M%S')}{videoManufacturer}{ext}"
|
||||||
safe_rename(fpath, new_fname)
|
safe_rename(Path(fpath),folder / new_fname)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 4. Fallback: keep original name, add _RX_<random> (only if not already added)
|
# 4. Fallback: keep original name, add _RX_<random> (only if not already added)
|
||||||
@@ -220,7 +222,7 @@ def process_images(folder):
|
|||||||
basename, _ = os.path.splitext(fname)
|
basename, _ = os.path.splitext(fname)
|
||||||
rand_num = random.randint(100000, 999999)
|
rand_num = random.randint(100000, 999999)
|
||||||
new_fname = f"{basename}_RX_{rand_num}{videoManufacturer}{ext}"
|
new_fname = f"{basename}_RX_{rand_num}{videoManufacturer}{ext}"
|
||||||
safe_rename(fpath, new_fname)
|
safe_rename(Path(fpath),folder / new_fname)
|
||||||
|
|
||||||
# ---- Main script entry ----
|
# ---- Main script entry ----
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
PW=$(cat /home/lucas/.PW)
|
PW=$(cat /home/lucas/.PW)
|
||||||
FOLDER=/torrent/Camera
|
FOLDER=/torrent/Camera
|
||||||
SERVER="https://someoneslinux.ddns.net"
|
SERVER="https://someoneslinux.ddns.net"
|
||||||
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&
|
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&1
|
||||||
|
export PYTHONPATH=/home/lucas/scripts
|
||||||
/home/lucas/.venv_general/bin/python3 /home/lucas/scripts/serverhost/rename_camera_folder.py ${FOLDER}
|
/home/lucas/.venv_general/bin/python3 /home/lucas/scripts/serverhost/rename_camera_folder.py ${FOLDER}
|
||||||
|
|
||||||
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&1
|
nextcloudcmd --trust --user lucas --password ${PW} --path Media/Pictures/Camera ${FOLDER} ${SERVER} 1>/dev/null 2>&1
|
||||||
Reference in new issue
Block a user