Example #1
0
def LGparser(AlexaCommand):
    if len(AlexaCommand) < 1:
        usage("Too few arguments")
    elif AlexaCommand[0] == "scan":
        results = LGTVScan()
        if len(results) > 0:
            print(
                json.dumps(
                    {
                        "result": "ok",
                        "count": len(results),
                        "list": results
                    },
                    sort_keys=True,
                    indent=4))
        else:
            print(
                json.dumps({
                    "result": "failed",
                    "count": len(results)
                },
                           sort_keys=True,
                           indent=4))

    elif AlexaCommand[0] == "on":
        ws = LGTVClient()
        ws.on()

    elif AlexaCommand[0] == "auth":
        if len(AlexaCommand) < 2:
            usage("Hostname or IP is required for auth")

        if os.path.exists("lgtv.json"):
            os.remove("lgtv.json")

        ws = LGTVClient(AlexaCommand[1])
        ws.connect()
        ws.run_forever()
    else:
        try:
            ws = LGTVClient()
            try:
                if (AlexaCommand[0] == "setTVChannel"):
                    AlexaCommand[1] = searchTVchannels(AlexaCommand[1])
                elif (AlexaCommand[0] == "startApp"):
                    AlexaCommand[1] = searchApps(AlexaCommand[1])
                args = parseargs(AlexaCommand[0], AlexaCommand[1:])
            except Exception as e:
                usage(e.message)
            ws.connect()
            ws.exec_command(AlexaCommand[0], args)
            ws.run_forever()
        except KeyboardInterrupt:
            ws.close()
Example #2
0

if __name__ == '__main__':
    if len(sys.argv) < 2:
        usage("Too few arguments")
    elif sys.argv[
            1] == "notificationWithURL":  #or sys.argv[1] == "notificationWithIcon":
        if len(sys.argv) < 4:
            usage("message and url required for {0}".format(sys.argv[1]))
        elif not which("ffmpeg") or not which(
                "base64") and sys.argv[1] == "notificationWithURL":
            usage("ffmpeg or base64 NOT found and required for {0}".format(
                sys.argv[1]))
        else:
            try:
                ws = LGTVClient()
                try:
                    args = parseargs(sys.argv[1], sys.argv[2:])
                except Exception as e:
                    usage(e.message)
                ws.connect()
                ws.exec_command(sys.argv[1], args)
                ws.run_forever()
            except KeyboardInterrupt:
                ws.close()
    elif sys.argv[1] == "scan":
        results = LGTVScan()
        if len(results) > 0:
            print(
                json.dumps({
                    "result": "ok",
Example #3
0
def main():
    if len(sys.argv) < 2:
        usage("Too few arguments")
    elif sys.argv[1] == "scan":
        results = LGTVScan()
        if len(results) > 0:
            print(
                json.dumps(
                    {
                        "result": "ok",
                        "count": len(results),
                        "list": results
                    },
                    sort_keys=True,
                    indent=4))
        else:
            print(
                json.dumps({
                    "result": "failed",
                    "count": len(results)
                },
                           sort_keys=True,
                           indent=4))
    elif sys.argv[1] == "on":
        ws = LGTVClient()
        ws.on()
    elif sys.argv[1] == "auth":
        if len(sys.argv) < 3:
            usage("Hostname or IP is required for auth")

        if os.path.exists(dirpath + ".lgtv.json"):
            os.remove(dirpath + ".lgtv.json")

        ws = LGTVClient(sys.argv[2])
        ws.connect()
        ws.run_forever()
    else:
        try:
            ws = LGTVClient()
            try:
                args = parseargs(sys.argv[1], sys.argv[2:])
            except Exception as e:
                usage(e.message)
            ws.connect()
            ws.exec_command(sys.argv[1], args)
            ws.run_forever()
        except KeyboardInterrupt:
            ws.close()