Last active
February 25, 2017 12:42
-
-
Save cbrwn/40fd56c122e58e982f72d21c1950cbf7 to your computer and use it in GitHub Desktop.
this sucks real bad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import ftplib | |
import os | |
import random | |
import string | |
import subprocess | |
import time | |
# stuff to change | |
ftp_host = "examples.com" | |
ftp_port = 21 | |
ftp_user = "exampleuser" | |
ftp_pass = "very-strong-password" | |
ftp_upload_to_folder = "/where/to/upload" | |
destination_url = "https://example.com/where/to/upload/" | |
upload_image_name_length = 4 # make a random name with this length | |
# Why isn't it easy to just play a sound in python | |
# Scrot's terrible too | |
# it's probably faster to write a sharex clone in cpp instead of spending the time I spent trying to simply play a fucking sound | |
# I hate python | |
# you need xclip & libnotify or something idfk | |
temp_image = "/tmp/screenshotimg.png" | |
def copy_to_clipboard(contents): | |
copy = os.popen("echo \"" + contents + "\" | xclip -selection clipboard") | |
def send_notification(notification): | |
subprocess.Popen(['notify-send', notification]) | |
# delete temp image | |
if os.path.isfile(temp_image): | |
os.remove(temp_image) | |
# make sure we end with a / | |
if not destination_url.endswith("/"): | |
destination_url += "/" | |
# wait a second so releasing keys won't break it | |
time.sleep(1) | |
# take screenshot | |
send_notification("Take screenshot of area...") | |
scrot = os.popen('scrot -s ' + temp_image) | |
result = scrot.read() # wait for scrot to finish | |
if not os.path.isfile(temp_image): | |
send_notification("Screenshot cancelled") | |
else: | |
send_notification("Screenshot taken! Uploading...") | |
# make new ftp session | |
ftpsession = ftplib.FTP() | |
# connect | |
ftpsession.connect(ftp_host, ftp_port) | |
# login | |
ftpsession.login(ftp_user, ftp_pass) | |
# move to folder | |
ftpsession.cwd(ftp_upload_to_folder) | |
# grab our image | |
screenshot = open(temp_image, 'rb') | |
new_image_name = ''.join(random.choices(string.ascii_uppercase + string.digits, k=upload_image_name_length)) + ".png" | |
# throw image onto server | |
ftpsession.storbinary("STOR " + new_image_name, screenshot) | |
screenshot.close() | |
ftpsession.quit() | |
# copy and tell us about it | |
image_destination = destination_url + new_image_name | |
copy_to_clipboard(image_destination) | |
send_notification("Copied to clipboard\n" + image_destination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment