From da276cb2e89010de18fd79f5798cd6de0fcd996f Mon Sep 17 00:00:00 2001 From: Dolan O'Toole Date: Sun, 9 Oct 2016 21:56:25 +0100 Subject: [PATCH 1/2] added screenshot subcommand to imgur plugin --- imgur.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/imgur.py b/imgur.py index db5173b..3f0d567 100644 --- a/imgur.py +++ b/imgur.py @@ -6,6 +6,7 @@ Requires imgur API """ import prof +import subprocess from os import path from imgurpython import ImgurClient @@ -16,13 +17,20 @@ client_secret = 'dd5b0918a2f5d36391d574bd2061c50b47bade63' client = ImgurClient(client_id, client_secret) -def _cmd_imgur(img_path): +def _cmd_imgur(arg1): + if arg1 == "screenshot": + file_path = "/tmp/_prof_scrot.png" + command = "scrot " + file_path + subprocess.call(command, shell=True) + else: + try: + file_path = path.expanduser(arg1) + except IOError as ioe: + prof.cons_show('Could not find file at ' + file_path) + return try: - expanded_path = path.expanduser(img_path) - data = client.upload_from_path(expanded_path, config=None, anon=True) + data = client.upload_from_path(file_path, config=None, anon=True) prof.send_line(data['link']) - except IOError as ioe: - prof.cons_show('Could not find file at ' + expanded_path) except ImgurClientError as e: prof.log_error('Could not upload to Imgur - ' + e.error_message) prof.log_error('Imgur status code - ' + e.status_code) @@ -30,14 +38,18 @@ def _cmd_imgur(img_path): def prof_init(version, status, account_name, fulljid): synopsis = [ - "/imgur " + "/imgur ", + "/imgur screenshot" ] - description = "Upload an image to imgur and send the link" + description = "Upload an image or screenshot to imgur and send the link" args = [ - [ "", "full path to image file" ] + [ "", "full path to image file" ], + [ "screenshot", "upload a full screen capture" ] ] examples = [ - "/imgur ~/images/cats.jpg" + "/imgur ~/images/cats.jpg", + "/imgur screenshot" ] prof.register_command("/imgur", 1, 1, synopsis, description, args, examples, _cmd_imgur) + prof.completer_add("/imgur", [ "screenshot" ]) From 9506e2460917a2d80b9d5a3984222d20060b5d59 Mon Sep 17 00:00:00 2001 From: Dolan O'Toole Date: Sun, 9 Oct 2016 22:00:23 +0100 Subject: [PATCH 2/2] adding requirements comment --- imgur.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgur.py b/imgur.py index 3f0d567..d2ac582 100644 --- a/imgur.py +++ b/imgur.py @@ -1,7 +1,8 @@ """ Requires imgur API pip install imgurpython - +Requires scrot installed for screenshot + sudo apt-get install scrot """