From f8ce7acd7e96178eb2779b26bb4f01ff774795d1 Mon Sep 17 00:00:00 2001 From: kageru Date: Wed, 18 Jul 2018 09:37:10 +0200 Subject: [PATCH] reenable and fix thumbnails --- pyshare.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pyshare.py b/pyshare.py index c996cb8..523b6d1 100755 --- a/pyshare.py +++ b/pyshare.py @@ -4,11 +4,13 @@ from string import ascii_letters, digits from argparse import ArgumentParser from pysftp import Connection from subprocess import call, check_output +from collections import namedtuple from random import choices from datetime import date from PIL import Image import pyperclip import config +import time import sys import os import re @@ -49,15 +51,20 @@ def upload_local_file(path: str) -> None: url = config.url_template.format(filename) else: url = curl_upload(path) - notify_user(url) + notify_user(url, path) -def take_screenshot(edit=False) -> None: +def prepare_file(ext: str) -> str: + "Generate a file name according to the config and create folder structure if necessary" full_path = get_local_full_path() if not os.path.exists(full_path): os.makedirs(full_path) - tempname = generate_filename(config.length, 'png') - file = os.path.join(get_local_full_path(), tempname) + tempname = generate_filename(config.length, ext) + return os.path.join(get_local_full_path(), tempname) + + +def take_screenshot(edit=False) -> None: + file = prepare_file('png') call(['maim', '-suk', file]) Image.open(file).convert('RGB').save(file) if edit: @@ -121,6 +128,7 @@ def notify_user(url:str, image=None) -> None: thumbnail = os.path.join(config.local_directory, 'thumb.jpg') img.save(thumbnail) call(['notify-send', '-a', 'pyshare', url, '-i', thumbnail, '-t', '3000']) + time.sleep(0.2) # delay slightly before deleting the file so notify-send can actually read it os.remove(thumbnail) else: call(['notify-send', '-a', 'pyshare', url, '-t', '3000'])