reenable and fix thumbnails

This commit is contained in:
kageru 2018-07-18 09:37:10 +02:00
parent 645dd6ac1d
commit f8ce7acd7e
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

View File

@ -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'])