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 argparse import ArgumentParser
from pysftp import Connection from pysftp import Connection
from subprocess import call, check_output from subprocess import call, check_output
from collections import namedtuple
from random import choices from random import choices
from datetime import date from datetime import date
from PIL import Image from PIL import Image
import pyperclip import pyperclip
import config import config
import time
import sys import sys
import os import os
import re import re
@ -49,15 +51,20 @@ def upload_local_file(path: str) -> None:
url = config.url_template.format(filename) url = config.url_template.format(filename)
else: else:
url = curl_upload(path) 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() full_path = get_local_full_path()
if not os.path.exists(full_path): if not os.path.exists(full_path):
os.makedirs(full_path) os.makedirs(full_path)
tempname = generate_filename(config.length, 'png') tempname = generate_filename(config.length, ext)
file = os.path.join(get_local_full_path(), tempname) return os.path.join(get_local_full_path(), tempname)
def take_screenshot(edit=False) -> None:
file = prepare_file('png')
call(['maim', '-suk', file]) call(['maim', '-suk', file])
Image.open(file).convert('RGB').save(file) Image.open(file).convert('RGB').save(file)
if edit: if edit:
@ -121,6 +128,7 @@ def notify_user(url:str, image=None) -> None:
thumbnail = os.path.join(config.local_directory, 'thumb.jpg') thumbnail = os.path.join(config.local_directory, 'thumb.jpg')
img.save(thumbnail) img.save(thumbnail)
call(['notify-send', '-a', 'pyshare', url, '-i', thumbnail, '-t', '3000']) 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) os.remove(thumbnail)
else: else:
call(['notify-send', '-a', 'pyshare', url, '-t', '3000']) call(['notify-send', '-a', 'pyshare', url, '-t', '3000'])