initial commit
This commit is contained in:
commit
20302a19ae
|
@ -0,0 +1,15 @@
|
||||||
|
# (S)FTP credentials
|
||||||
|
sftp_address = 'your_domain.com'
|
||||||
|
username = 'your_ftp_user'
|
||||||
|
password = 'your_ftp_password'
|
||||||
|
|
||||||
|
# This is where the screenshots are saved locally
|
||||||
|
local_directory = '/home/kageru/pyshare/'
|
||||||
|
# Directory on the ftp server where you want the screenshots to be sent to
|
||||||
|
remote_directory = '/usr/share/nginx/html/pyshare/'
|
||||||
|
# Template for the link that the script will generate. {} is the filename
|
||||||
|
link_template = 'https://your_domain.com/pyshare/{}'
|
||||||
|
# In case you want a certain prefix for all files. Can also be an empty string
|
||||||
|
prefix = ''
|
||||||
|
# Number of random characters in the filename
|
||||||
|
length = 5
|
|
@ -0,0 +1,46 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from subprocess import call
|
||||||
|
import os
|
||||||
|
from pysftp import Connection
|
||||||
|
from tkinter import Tk, Button
|
||||||
|
from string import ascii_letters, digits
|
||||||
|
from random import choices
|
||||||
|
import config
|
||||||
|
|
||||||
|
character_pool = ascii_letters + digits
|
||||||
|
|
||||||
|
def generate_filename(prefix, length):
|
||||||
|
return prefix + ''.join(choices(character_pool, k=length)) + '.png'
|
||||||
|
|
||||||
|
|
||||||
|
filename = generate_filename(config.prefix, config.length)
|
||||||
|
|
||||||
|
with Connection(config.sftp_address, username=config.username, password=config.password) as conn:
|
||||||
|
with conn.cd(config.remote_directory):
|
||||||
|
# there's potential for an endless loop here...
|
||||||
|
while conn.exists(filename):
|
||||||
|
filename = generate_filename(config.prefix, config.length)
|
||||||
|
|
||||||
|
filepath = os.path.join(config.local_directory, filename)
|
||||||
|
|
||||||
|
call(["escrotum", "{}".format(filepath), "-s"])
|
||||||
|
|
||||||
|
conn.put(filepath)
|
||||||
|
|
||||||
|
link = config.link_template.format(filename)
|
||||||
|
|
||||||
|
# copy link to clipboard
|
||||||
|
# https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python#4203897
|
||||||
|
print(link)
|
||||||
|
r = Tk()
|
||||||
|
r.clipboard_clear()
|
||||||
|
r.clipboard_append(link)
|
||||||
|
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"{link}", font=("Verdana", 12), bg="black", command=sys.exit)
|
||||||
|
rButton.pack()
|
||||||
|
r.geometry('400x50+700+500')
|
||||||
|
r.mainloop()
|
Loading…
Reference in New Issue
Block a user