refactor: rename RANDOM_FILE_PICKER_MEME_FOLDER to RANDOM_FILE_PICKER_MOVE_FOLDER

This commit is contained in:
2026-07-15 14:42:14 +03:00
parent 5667833907
commit 290e79b7b1
2 changed files with 22 additions and 22 deletions
+14 -14
View File
@@ -6,7 +6,7 @@ import pathlib
import requests
WEBHOOK_URL = os.environ.get("RANDOM_FILE_PICKER_WEBHOOK_URL", None)
MEME_FOLDER = os.environ.get("RANDOM_FILE_PICKER_MEME_FOLDER", None)
MOVE_FOLDER = os.environ.get("RANDOM_FILE_PICKER_MOVE_FOLDER", None)
SUPPORTED_EXTENSIONS = [
".jpg", ".jpeg",
@@ -83,31 +83,31 @@ def upload_file(file_path: pathlib.Path) -> None:
response = requests.post(WEBHOOK_URL, files=files, data={}, timeout=60*5)
response.raise_for_status() # Raise HTTPError for bad responses
def move_file_to_meme_folder(file_path: pathlib.Path) -> None:
def move_file_to_move_folder(file_path: pathlib.Path) -> None:
"""
Move the specified file to the meme folder defined by the RANDOM_FILE_PICKER_MEME_FOLDER environment variable.
Move the specified file to the move folder defined by the RANDOM_FILE_PICKER_MOVE_FOLDER environment variable.
:param file_path: The path of the file to be moved.
"""
if MEME_FOLDER is None:
raise ValueError("RANDOM_FILE_PICKER_MEME_FOLDER environment variable is not set.")
meme_dir_path = pathlib.Path(MEME_FOLDER)
if MOVE_FOLDER is None:
raise ValueError("RANDOM_FILE_PICKER_MOVE_FOLDER environment variable is not set.")
move_dir_path = pathlib.Path(MOVE_FOLDER)
# Make sure the meme folder exists
if not meme_dir_path.exists():
raise RuntimeError(f"Meme folder '{meme_dir_path}' does not exist.")
# Make sure the move folder exists
if not move_dir_path.exists():
raise RuntimeError(f"Move folder '{move_dir_path}' does not exist.")
# Make sure the file being moved is not already in the meme folder
if file_path.parent.resolve() == meme_dir_path.resolve():
raise RuntimeError("File is already in the meme folder.")
# Make sure the file being moved is not already in the move folder
if file_path.parent.resolve() == move_dir_path.resolve():
raise RuntimeError("File is already in the move folder.")
# Formulate the destination path and avoid overwriting existing files
base_name = file_path.name
destination_path = meme_dir_path / base_name
destination_path = move_dir_path / base_name
if destination_path.exists():
name, ext = destination_path.stem, destination_path.suffix
counter = 1
while destination_path.exists():
destination_path = meme_dir_path / f"{name}_{counter}{ext}"
destination_path = move_dir_path / f"{name}_{counter}{ext}"
counter += 1
_ = file_path.rename(destination_path)
+8 -8
View File
@@ -15,7 +15,7 @@ from textual.app import App, ComposeResult
from textual.binding import BindingType
from textual.widgets import Footer, Header, Label
from random_file_picker.core import collect_files, move_file_to_meme_folder, upload_file
from random_file_picker.core import collect_files, move_file_to_move_folder, upload_file
from random_file_picker.openers import open_file_in_dolphin, open_file_with_default_app, open_file_with_geeqie
IMG_EXTENSIONS = [
@@ -38,7 +38,7 @@ class MenuApp(App[None]):
("r", "reopen_file", "Reopen"),
("u", "upload", "Upload"),
("d", "delete", "Delete"),
("m", "move_to_meme", "Move Meme"),
("m", "move_to_folder", "Move File"),
("f", "open_folder", "Open Folder"),
("q", "quit", "Quit"),
]
@@ -158,15 +158,15 @@ class MenuApp(App[None]):
except Exception as e:
self.query_one("#status", Label).update(f"❌ Delete failed: {str(e)}")
def move_to_meme_folder(self) -> None:
"""Move the current file to the meme folder."""
def move_to_move_folder(self) -> None:
"""Move the current file to the move folder."""
if not self.current_file or self.current_index >= len(self.usable_files):
return
try:
move_file_to_meme_folder(self.current_file)
move_file_to_move_folder(self.current_file)
_ = self.usable_files.pop(self.current_index)
self.query_one("#status", Label).update("✅ Moved to meme folder")
self.query_one("#status", Label).update("✅ Moved to move folder")
# Adjust index if we removed the last file
if self.current_index >= len(self.usable_files) and self.usable_files:
@@ -193,8 +193,8 @@ class MenuApp(App[None]):
def action_delete(self) -> None:
self.delete_file()
def action_move_to_meme(self) -> None:
self.move_to_meme_folder()
def action_move_to_folder(self) -> None:
self.move_to_move_folder()
def action_open_folder(self) -> None:
self.open_in_folder()