From 7c8631f9ea6ed4d81b98f13b42de7057433db5b2 Mon Sep 17 00:00:00 2001 From: retrilzzy Date: Wed, 1 Jan 2025 20:38:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B1=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BA=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=88=D0=BE=D1=82=D0=B0=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D0=BE=D0=B1=D0=BB=D0=B0=D1=81=D1=82=D0=B8?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20=D0=B2=20?= =?UTF-8?q?Chibisafe=20=D0=B8=20=D0=BA=D0=BE=D0=BF=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=89=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=83=D0=BF=D0=BD=D0=BE=D0=B9=20=D1=81=D1=81=D1=8B?= =?UTF-8?q?=D0=BB=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configs/hypr/keybindings.conf | 20 +++-- Configs/hypr/scripts/.env.example | 6 ++ Configs/hypr/scripts/chibisafe_uploader.py | 78 +++++++++++++++++++ .../hypr/scripts/screenshot_to_chibisafe.sh | 15 ++++ 4 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 Configs/hypr/scripts/.env.example create mode 100644 Configs/hypr/scripts/chibisafe_uploader.py create mode 100755 Configs/hypr/scripts/screenshot_to_chibisafe.sh diff --git a/Configs/hypr/keybindings.conf b/Configs/hypr/keybindings.conf index ff94535..2d03769 100644 --- a/Configs/hypr/keybindings.conf +++ b/Configs/hypr/keybindings.conf @@ -51,6 +51,18 @@ bind = $mainMod, L, exec, $HOME/.config/wlogout/current_wall.sh && loginctl lock bindl = $mainMod ALT, D, exec, hyprctl dispatch dpms toggle bindl = $mainMod ALT, S, exec, $HOME/.config/wlogout/current_wall.sh && systemctl suspend +# Screenshot a window +bind = $mainMod, PRINT, exec, hyprshot -z -m window -o ~/Pictures/Screen +# Screenshot of a region +bind = SHIFT, Print, exec, grim -c -g "$(slurp)" - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of the region taken" -t 2000 +# Screenshot of the whole screen +bind = , Print, exec, grim -c - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of whole screen taken" -t 2000 +# Screenshot of a region and upload to Chibisafe +bind = $mainMod SHIFT, PRINT, exec, $HOME/.config/hypr/scripts/screenshot_to_chibisafe.sh + +# Emoji Picker +bind = $mainMod SHIFT, E, exec, emote + # Move focus with mainMod + arrow keys bind = $mainMod, left, movefocus, l bind = $mainMod, right, movefocus, r @@ -121,11 +133,3 @@ bindl = , XF86AudioNext, exec, playerctl next bindl = , XF86AudioPause, exec, playerctl play-pause bindl = , XF86AudioPlay, exec, playerctl play-pause bindl = , XF86AudioPrev, exec, playerctl previous - -# Screenshots -bind = $mainMod, PRINT, exec, hyprshot -z -m window -o ~/Pictures/Screen # Screenshot a window -bind = SHIFT, Print, exec, grim -c -g "$(slurp)" - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of the region taken" -t 2000 # Screenshot of a region -bind = , Print, exec, grim -c - | wl-copy && wl-paste > ~/Pictures/Screen/$(date +%F_%T)-grim.png | notify-send "Screenshot of whole screen taken" -t 2000 # Screenshot of the whole screen - -# Emoji Picker -bind = $mainMod SHIFT, E, exec, emote diff --git a/Configs/hypr/scripts/.env.example b/Configs/hypr/scripts/.env.example new file mode 100644 index 0000000..ed5ed00 --- /dev/null +++ b/Configs/hypr/scripts/.env.example @@ -0,0 +1,6 @@ +# ChibiSafe URL for accessing your service +CHIBISAFE_URL=https://chibisafe.example + +# ChibiSafe API token, which can be obtained from your account dashboard (https://chibisafe.example/dashboard/account) +CHIBISAFE_API_TOKEN=your_api_token + diff --git a/Configs/hypr/scripts/chibisafe_uploader.py b/Configs/hypr/scripts/chibisafe_uploader.py new file mode 100644 index 0000000..d07e327 --- /dev/null +++ b/Configs/hypr/scripts/chibisafe_uploader.py @@ -0,0 +1,78 @@ +""" +A simple Chibisafe file uploader that uses the Chibisafe API and API key to upload files. + +It is designed for Linux distros running Wayland (I use Arch Linux + Hyprland). + +If it doesn't work on your system, check the commands in the functions: +`send_notification()` and `copy_to_clipboard()` + +Usage: + python3.12 chibisafe_uploader.py /path/to/file +""" + +import os +import mimetypes +import requests +import dotenv +import logging +import argparse + + +logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') +logger = logging.getLogger(__name__) + +dotenv.load_dotenv() + + +def send_notification(message: str) -> None: + os.system(f'notify-send "ChibisafeUploader" "{message}" -t 3000') + +def copy_to_clipboard(url: str) -> None: + os.system(f'echo "{url}" | wl-copy') + + +def upload_file(file_path: str) -> None: + """ + Upload a file to Chibisafe API. + """ + if not os.path.exists(file_path): + logger.error(f"Error. File {file_path} not found.") + send_notification(f"❌ File {file_path} not found.") + return + + + file_name = os.path.basename(file_path) + mime_type, _ = mimetypes.guess_type(file_path) + + try: + response = requests.post( + url=f"{os.getenv("CHIBISAFE_URL")}/api/upload", + + headers={ + "x-api-key": os.getenv("CHIBISAFE_API_TOKEN"), + "user-agent": "Mozilla/5.0 Chrome/131.0.0.0 Safari/537.36", + }, + + files={ + "file": (file_name, open(file_path, "rb"), mime_type or "application/octet-stream"), + }, + ) + response.raise_for_status() + logger.info(f"Successful. API response: {response.json()}") + + send_notification("✅ File uploaded successfully") + copy_to_clipboard(response.json()["url"]) + + except requests.exceptions.RequestException as e: + logger.error(f"Error occurred while uploading file.\n{e}") + send_notification(f"❌ Error occurred while uploading file.\n{e}") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="A simple Chibisafe file uploader that uses the Chibisafe API to upload files." + ) + parser.add_argument("file_path", help="Full path to the file to upload") + args = parser.parse_args() + + upload_file(args.file_path) diff --git a/Configs/hypr/scripts/screenshot_to_chibisafe.sh b/Configs/hypr/scripts/screenshot_to_chibisafe.sh new file mode 100755 index 0000000..adf8e14 --- /dev/null +++ b/Configs/hypr/scripts/screenshot_to_chibisafe.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +TEMP_DIR="/tmp" +FILENAME="$(date +%F_%T)-grim.png" +FILE_PATH="$TEMP_DIR/$FILENAME" + +# Take the screenshot of the region +grim -c -g "$(slurp)" "$FILE_PATH" || exit 1 + +# Upload the screenshot to ChibiSafe with Python script +"$HOME/.config/hypr/scripts/.venv/bin/python3.12" "$HOME/.config/hypr/scripts/chibisafe_uploader.py" "$FILE_PATH" + +rm "$FILE_PATH"