Code: Alles auswählen
from lxml import etree, cssselect
import webbrowser, requests
import time, os, sys, subprocess
URL = "http://www.directupload.net/index.php"
PAYLOAD = {"mode": "upload", "input": "file", "Upload_file": "image"}
DIRECTORY = "/was/auch/immer"
TIME_FORMAT = "%d.%m.%Y_%H.%M.%S"
def save_screenshot(filepath):
if "mode=full" in sys.argv:
subprocess.call(["screencapture", filepath])
else:
subprocess.call(["screencapture", "-i", filepath])
#in case interactive screenshot capture got canceled
if not os.path.exists(filepath):
sys.exit(0)
def upload_file(filename, filepath):
file = {"bilddatei": (filename, open(filepath, "rb"))}
r = requests.post(URL, data=PAYLOAD, files=file)
return r.content
def get_direct_link(content):
html = etree.HTML(content)
selector = cssselect.CSSSelector('a[target="_blank"] img')
direct_link = selector(html)[2].get("src")
return direct_link
def main():
filename = "{}.png".format(time.strftime(TIME_FORMAT, time.gmtime()))
filepath = os.path.join(DIRECTORY, filename)
save_screenshot(filepath)
page_content = upload_file(filename, filepath)
url = get_direct_link(page_content)
webbrowser.open(url)
if __name__ == "__main__":
main()