From 6ce497b6539c198d3c2e857ecd9916a549dd9899 Mon Sep 17 00:00:00 2001 From: kageru <8497max@gmail.com> Date: Wed, 25 Oct 2017 14:22:58 +0200 Subject: [PATCH] more refactoring for more modes --- pyshare.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/pyshare.py b/pyshare.py index 3342c4e..c2b677d 100644 --- a/pyshare.py +++ b/pyshare.py @@ -10,11 +10,13 @@ from random import choices import config character_pool = ascii_letters + digits +tk = Tk() def generate_filename(prefix, length, ext): return prefix + ''.join(choices(character_pool, k=length)) + '.' + ext + def find_filename(prefix, length, ext, conn): filename = generate_filename(prefix, length, ext) i = 0 @@ -22,12 +24,12 @@ def find_filename(prefix, length, ext, conn): filename = generate_filename(prefix, length, ext) i += 1 if i > 1000: - # using recursion here feels... questionable at best, but it's faster than using % every loop + # completely, definitely, totally justified recursion... yay? find_filename(prefix, length + 1, ext, conn) -def upload_local_file(path: str, - conn: Connection) -> Exception: # does this even return an exception? probably not. does it matter? definitely not +def upload_local_file(path: str, conn: Connection) -> Exception: + # does this even return an exception? probably not. does it matter? definitely not raise NotImplementedError('soon(tm)') @@ -54,23 +56,27 @@ def curl_upload(filename): if config.custom_curl_command is not None: return call(config.custom_curl_command) else: - return call(f'curl -k -F"file=@{filename}" -F"name={config.username}" -F"passwd={config.password}" {config.curl_target}') + return call( + f'curl -k -F"file=@{filename}" -F"name={config.username}" -F"passwd={config.password}" {config.curl_target}') + + +def set_clipboard(text): + tk.clipboard_clear() + tk.clipboard_append(text) + + +def get_clipboard(): + result = tk.selection_get(selection="CLIPBOARD") def notify_user(url): print(url) - # copy link to clipboard - # https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python#4203897 - r = Tk() - r.clipboard_clear() - r.clipboard_append(url) - r.after(2000, sys.exit) # also show a little button that does nothing. # Well, it informs you that your link is ready, so that's something, I guess - rButton = Button(r, text=f"{url}", font=("Verdana", 12), bg="black", command=sys.exit) + rButton = Button(tk, text=f"{url}", font=("Verdana", 12), bg="black", command=sys.exit) rButton.pack() - r.geometry('400x50+700+500') - r.mainloop() + tk.geometry('400x50+700+500') + tk.mainloop() if __name__ == '__main__': @@ -81,6 +87,14 @@ if __name__ == '__main__': else: mode = 'screenshot' ext = 'png' + if mode == 'screenshot': + pass + elif mode=='file': + pass + elif mode=='text': + pass + + """ if config.uploader in ['ftp', 'sftp']: if mode != 'screenshot' and '.' in file: ext = '.' + file.rsplit('.', 1)[1] @@ -99,3 +113,4 @@ if __name__ == '__main__': sys.exit(-1) url = config.url_template.format(filename) notify_user(url) + """