Skip to content

Instantly share code, notes, and snippets.

@twnlink
Last active September 30, 2019 11:08
Show Gist options
  • Save twnlink/49d32952072638a75d9f64c20c7b0e72 to your computer and use it in GitHub Desktop.
Save twnlink/49d32952072638a75d9f64c20c7b0e72 to your computer and use it in GitHub Desktop.
A simple Python screenshot tool for MacOS.
import os
import rumps
import tempfile
import requests
import json
import pyperclip
import random
import sys
# CONFIG
uploadurl = "https://api.mirage.re/upload"
# random domain pool
outputbaseurls = ["mirage.rocks"]
# when false will use first domain in outputbaseurls
randomdomains = False
# when true will enable i-am.a-virg.in URL shortening
virgins = False
# mirage.photos API key, you can get this from your Mirage management page
apikey = ""
if sys.platform != "darwin":
print("I'm sorry, it looks like you aren't using MacOS so Barstool has exited.")
sys.exit()
class BarstoolPy(rumps.App):
@rumps.clicked("Take screenshot")
def shortshot(self, _):
if randomdomains:
imagedomain = random.choice(outputbaseurls)
else:
imagedomain = outputbaseurls[0]
tempdir = tempfile.gettempdir() + "/"
screenshotpath = tempdir + "barstoolpyscreenshot.png"
os.system('screencapture -i ' + screenshotpath)
if os.path.exists(screenshotpath):
file = {'file': ('screenshot.png', open(screenshotpath, 'rb'), 'image/png')}
upload = requests.post(uploadurl, files = file, data = {"key":apikey,"host":imagedomain})
print(upload.text)
if upload.text != "Upload key is invalid":
pyperclip.copy(upload.text)
os.remove(screenshotpath)
if random.randint(0, 1) == 0 and virgins:
shortenreq = requests.post('https://i-am.a-virg.in/api/shorten', params = {'link': upload.text})
if shortenreq.status_code == 200:
pyperclip.copy(json.loads(shortenreq.text)['url'])
if __name__ == "__main__":
BarstoolPy("✂️").run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment