예제 #1
0
def list_collector(query="",kind="scenes"):
    global TYPES, COMMANDS, VERBS
    #print("list_collector: query is {query}").format(query=query)

    feedback_list = []
    feedback = Feedback()

    if not kind in TYPES:
        return feedback

    args = string.split(query, " ")    
    executable = False
    
    term = ''
    command = None
    for currentArg in args:
        if currentArg in COMMANDS or currentArg.isdigit():
            command, currentArg = choose_command(command, currentArg)
            executable = True
        if currentArg != command and currentArg:
            term += ' {ca}'.format(ca=currentArg)
    term = term.strip()

    if command and command.isdigit():
        if(int(command) < 0):
            command = '0'
        elif (int(command) > 100):
            command = '100'
            
    results = hunterdouglas.find_by_name(kind, term)
    for result in results:
        label = result["name"]
        internal_id = result["id"]

        if len(term) > 0:
            if not term.lower() in label.lower():
                continue

        arg = "{kind}.{internal_id}.{command}".format(kind=kind, internal_id=internal_id, command=command)
        verb = VERBS[kind]

        executable=True
        if kind != "scenes" and not command:
            executable = False
            title = "{verb} {target}".format(verb=verb, target=label)
        elif kind != "scenes" and command in COMMANDS:
            title = "{verb} {command} {target}".format(verb=verb, command=command, target=label)
        elif kind != "scenes" and command.isdigit():
            title = "{verb} {target} to {command}% up".format(verb=verb, command=command, target=label)
        elif kind == "scenes":
            title = "{verb} {target}".format(verb=verb, target=label)
            
        if title:
            feedback_list.append({'title':title, 'subtitle':label, 'arg':arg, 'valid':executable, 'autocomplete':' {l} '.format(l=label)})    

    feedback_list = sorted(feedback_list, key=lambda k:k['subtitle'])
    for item in feedback_list:
        feedback.addItem(title=item['title'], subtitle=item['subtitle'], arg=item['arg'], valid=item['valid'], autocomplete=item['autocomplete'])
    
    return feedback
예제 #2
0
def list_collector(query=""):
    feedback = Feedback()
    query = query.lower().strip()
    parts = query.split(' ')
    password = len(parts) > 1 and parts[1] or ''
    query = parts[0].strip()
    if not query or "stay".startswith(query):
      feedback.addItem(title="Stay", subtitle="Arm in Stay mode", arg="stay "+password, valid=True, autocomplete="Stay "+password)
    if not query or "away".startswith(query):
      feedback.addItem(title="Away", subtitle="Arm in Away mode", arg="away "+password, valid=True, autocomplete="Away "+password)
    if not query or "off".startswith(query):
      feedback.addItem(title="Off", subtitle="Disarm the Alarm", arg="off "+password, valid=True, autocomplete=" Off "+password)
    
    return feedback
예제 #3
0
def login_command(query=""):
    stop()

    feedback = Feedback()

    if os.path.isfile("token.txt"):
        tokenFile = open("token.txt")
        token = tokenFile.read()
        tokenFile.close()
        if token.__len__() > 0:
            feedback.addItem(title="You are already authenticated with SmartThings")
            return feedback
    else:
        feedback.addItem(title="Authenticate with SmartThings",
                         subtitle="You will be forwarded to https://www.smartthings.com")
        return feedback
예제 #4
0
import os
import subprocess
import sys
import devices
from alfred import Feedback

feedback = Feedback()
adb = "/Library/Android/sdk/platform-tools/adb"
device = ""
if len(sys.argv) > 1 and len(sys.argv[1].strip()) > 0:
    device = " -s " + sys.argv[1]
cmd = adb + device + " shell dumpsys window windows | grep -E 'mCurrentFocus'"
process = subprocess.Popen(cmd.split(),
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE)
output, error = process.communicate()
if error is not None and "more than one" in error:
    devices.list()
    exit(0)
if error is not None and "no devices" in error:
    devices.list()
    exit(0)
result = os.popen(cmd).read().strip()
displayName = result.split(' ')[-1][0:-1]
parts = displayName.split("/")
packageName = None
className = None
simpleName = None
if len(parts) > 1:
    packageName = parts[0]
    className = parts[1]
예제 #5
0
def device_collector(query=""):
    stop()

    feedback = Feedback()

    args = string.split(query, " ")

    command = args[-1]
    if len(command) < 1:
        command = args[-2]

    switchCommandsFile = open("commands.switches.txt")
    switchCommands = switchCommandsFile.read()
    switchCommandsFile.close()

    lockCommandsFile = open("commands.locks.txt")
    lockCommands = lockCommandsFile.read()
    lockCommandsFile.close()

    executable = False
    if command in switchCommands or command in lockCommands:
        if len(command) > 0:
            executable = True
    else:
        command = ''

    deviceFilter = ''
    for currentArg in args:
        if currentArg != command:
            deviceFilter += ' {ca}'.format(ca=currentArg)

    deviceFilter = deviceFilter.strip()

    tokenFile = open("token.txt")
    token = tokenFile.read()
    tokenFile.close()

    with open("endpoints.txt", 'r') as fh:
        try:
            deviceFile = open("devices.txt")
            for deviceDataString in deviceFile.readlines():
                deviceData = string.split(deviceDataString, ":")
                deviceEndpoint = deviceData[0].strip()
                deviceLabel = deviceData[1].strip()

                if len(deviceFilter) > 0:
                    if not deviceFilter.lower() in deviceLabel.lower():
                        continue

                arg = "{deviceEndpoint}.{command}".format(
                    deviceEndpoint=deviceEndpoint, command=command)

                title = deviceLabel
                if command.__len__() > 1:
                    if command in switchCommands:
                        title = "Turn {command} {device}".format(
                            command=command, device=deviceLabel)
                    else:
                        title = "{command} {device}".format(
                            command=command.capitalize(), device=deviceLabel)

                feedback.addItem(title=title,
                                 subtitle=deviceLabel,
                                 arg=arg,
                                 valid=executable,
                                 autocomplete=' {l}'.format(l=deviceLabel))

            deviceFile.close()
        except IOError:
            print "Uh oh"

    return feedback
def device_collector(query=""):
    stop()

    feedback = Feedback()

    args = string.split(query, " ")

    command = args[-1]
    if len(command) < 1:
        command = args[-2]

    switchCommandsFile = open("commands.switches.txt")
    switchCommands = switchCommandsFile.read()
    switchCommandsFile.close()
    
    lockCommandsFile = open("commands.locks.txt")
    lockCommands = lockCommandsFile.read()
    lockCommandsFile.close()
    
    executable = False
    if command in switchCommands or command in lockCommands:
        if len(command) > 0:
            executable = True
    else:
        command = ''
    
    deviceFilter = ''
    for currentArg in args:
        if currentArg != command:
            deviceFilter += ' {ca}'.format(ca=currentArg)

    deviceFilter = deviceFilter.strip()

    tokenFile = open("token.txt")
    token = tokenFile.read()
    tokenFile.close()

    with open("endpoints.txt", 'r') as fh:
        try:
            deviceFile = open("devices.txt")
            for deviceDataString in deviceFile.readlines():
                deviceData = string.split(deviceDataString, ":")
                deviceEndpoint = deviceData[0].strip()
                deviceLabel = deviceData[1].strip()
    
                if len(deviceFilter) > 0:
                    if not deviceFilter.lower() in deviceLabel.lower():
                        continue
    
                arg = "{deviceEndpoint}.{command}".format(deviceEndpoint=deviceEndpoint, command=command)
                
                title = deviceLabel
                if command.__len__() > 1:
                    if command in switchCommands:
                        title = "Turn {command} {device}".format(command=command, device=deviceLabel)
                    else:
                        title = "{command} {device}".format(command=command.capitalize(), device=deviceLabel)
    
                feedback.addItem(title=title, subtitle=deviceLabel, arg=arg, valid=executable, autocomplete=' {l}'.format(l=deviceLabel))
            
            deviceFile.close()
        except IOError:
            print "Uh oh"
    
    return feedback
예제 #7
0
#!/usr/bin/python
from alfred import Feedback
from BeautifulSoup import BeautifulSoup as BS
import urllib2
import string
import sys

fb = Feedback()
term = ' '.join(sys.argv[1:])
with file('username.txt', 'rb') as f:
    username = f.read()

def pin_search(query,username):
  URL = 'http://www.pinboard.in/search/u:%s?query=%s' % (username,query)
  soup = BS(urllib2.urlopen(URL))
  for link in soup("a"):
    if "bookmark_title" in str(link):
      fb.add_item(link.string.strip(), subtitle=link['href'], arg=link['href'])
  print fb

if term[0:4] == "set ":
  username = term[4:]
  with file('username.txt', 'wb') as f:
    f.write(username)
  fb.add_item("Pinboard username set to %s" % username)
  print fb
elif len(term) > 3 and term[0:4] != "set ":
  pin_search(sys.argv[1:], username)
else:
  fb.add_item("Search results for %s shown for 4 or more characters" % username )
  print fb