From d7417bb3c670e4c30a8205723370eefbd690ce78 Mon Sep 17 00:00:00 2001 From: kageru Date: Wed, 22 Nov 2017 11:38:34 +0100 Subject: [PATCH] added thumbnails to screenshot upload notifications --- pyshare.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pyshare.py b/pyshare.py index 5961bfa..7dbffae 100755 --- a/pyshare.py +++ b/pyshare.py @@ -5,6 +5,7 @@ from argparse import ArgumentParser from pysftp import Connection from subprocess import call from random import choices +from PIL import Image import pyperclip import config import sys @@ -91,15 +92,23 @@ def curl_upload(filename): return call(config.custom_curl_command) -def notify_user(url): +def notify_user(url, image=None): print(url) pyperclip.copy(url) - call(['notify-send', url]) + if image: + img = Image.open(image) + img.thumbnail((384, 384), Image.ANTIALIAS) + thumbnail = os.path.join(config.local_directory, 'thumb.jpg') + img.save(thumbnail) + call(['notify-send', '-a pyshare', url, f'-i {thumbnail}', '-t 3000']) + os.remove(thumbnail) + else: + call(['notify-send', '-a pyshare', url, '-t 3000']) def parse_text(args): text = pyperclip.paste() - if re.match(r'https?://', text): + if re.match(r'(https?|s?ftp)://', text): mirror_file(text) elif os.path.isfile(text): upload_local_file(text)