From 3cdaa371ed7b47d8b2a52288ccb67d1f9f3265c5 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Thu, 3 Jan 2019 13:21:32 +0000 Subject: [PATCH] Add an extension to generate a random password --- org.albert.extension.python/modules/genpw.py | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 org.albert.extension.python/modules/genpw.py diff --git a/org.albert.extension.python/modules/genpw.py b/org.albert.extension.python/modules/genpw.py new file mode 100644 index 0000000..7e1ef87 --- /dev/null +++ b/org.albert.extension.python/modules/genpw.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- + +""" +The extension will generate a random string of the +specified length and copy it to the clipboard. +""" + +import os +import base64 + +from albertv0 import * + +__iid__ = "PythonInterface/v0.1" +__prettyname__ = "Password Generator" +__version__ = "1.0" +__trigger__ = "genpw " +__author__ = "Scott Wallace" +__dependencies__ = [] + + +ICON_PATH = iconLookup('dialog-password') + + +def handleQuery(query): + if query.isTriggered: + return generatePassword(query) + +def generatePassword(query): + length = int(query.string.strip()) + + return [Item( + id=__prettyname__, + icon=ICON_PATH, + text='Generate a new %s-character password' % length, + subtext='', + completion="%s %s" % (__trigger__, query.string), + actions=[ + ClipAction('Copy the new password to clipboard', + base64.encodestring(os.urandom(256))[:length]) + ] + )]