added clipboard operations (local path, url, plain text)
This commit is contained in:
parent
6ce497b653
commit
dcef91fdd6
35
pyshare.py
35
pyshare.py
|
@ -3,6 +3,8 @@
|
|||
import sys
|
||||
from subprocess import call
|
||||
import os
|
||||
|
||||
import re
|
||||
from pysftp import Connection
|
||||
from tkinter import Tk, Button
|
||||
from string import ascii_letters, digits
|
||||
|
@ -13,7 +15,7 @@ character_pool = ascii_letters + digits
|
|||
tk = Tk()
|
||||
|
||||
|
||||
def generate_filename(prefix, length, ext):
|
||||
def generate_filename(length, ext, prefix=''):
|
||||
return prefix + ''.join(choices(character_pool, k=length)) + '.' + ext
|
||||
|
||||
|
||||
|
@ -34,7 +36,7 @@ def upload_local_file(path: str, conn: Connection) -> Exception:
|
|||
|
||||
|
||||
def take_screenshot(filename: str) -> None:
|
||||
call(["escrotum", "{}".format(filename), "-s"])
|
||||
call(["escrotum", filename, "-s"])
|
||||
|
||||
|
||||
def ftp_upload(mode='screenshot', ext=None) -> tuple:
|
||||
|
@ -79,6 +81,23 @@ def notify_user(url):
|
|||
tk.mainloop()
|
||||
|
||||
|
||||
def mirror_file(text):
|
||||
os.chdir(config.local_directory)
|
||||
call(['wget', text])
|
||||
filename = text.rsplit('/')[-1]
|
||||
url = upload_local_file(os.path.join(config.local_directory, filename))
|
||||
os.remove(os.path.join(config.local_directory, filename))
|
||||
set_clipboard(url)
|
||||
notify_user(url)
|
||||
|
||||
|
||||
def upload_text(text):
|
||||
filename = generate_filename(config.length, 'txt')
|
||||
with open(os.path.join(config.local_directory, filename), 'w') as file:
|
||||
file.write(text)
|
||||
upload_local_file(os.path.join(config.local_directory, filename))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 1:
|
||||
mode = 'file'
|
||||
|
@ -89,10 +108,16 @@ if __name__ == '__main__':
|
|||
ext = 'png'
|
||||
if mode == 'screenshot':
|
||||
pass
|
||||
elif mode=='file':
|
||||
pass
|
||||
elif mode=='text':
|
||||
elif mode == 'file':
|
||||
pass
|
||||
elif mode == 'text':
|
||||
text = get_clipboard()
|
||||
if re.match(r'https?://', text):
|
||||
mirror_file(text)
|
||||
elif os.path.isfile(text):
|
||||
upload_local_file(text)
|
||||
else:
|
||||
upload_text(text)
|
||||
|
||||
"""
|
||||
if config.uploader in ['ftp', 'sftp']:
|
||||
|
|
Loading…
Reference in New Issue
Block a user