Example #1
0
def main():
    parser = parse_arguments(COMMANDS)
    arguments = parser.parse_args()

    if arguments.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    configfile = os.path.join(appdir, '.ptp.conf')

    if os.path.exists(configfile):
        config = parse_config(configfile)
    else:
        config = parse_env()

    ptpobj = ptp.PTP(config.get('ptp', {}).get('ApiUser'),
                     config.get('ptp', {}).get('ApiKey'),
                     appdir,
                     logger=LOG)

    clientparser = parse_arguments(CLIENT_COMMANDS,
                                   prog=PTPClient.prefix,
                                   add_help=False)

    client = PTPClient(ptpobj, clientparser)
    client.run(config.get('discord', {}).get('token'))
Example #2
0
def main():
    parser = parse_arguments(COMMANDS)
    arguments = parser.parse_args()

    if arguments.debug:
      logging.basicConfig(level=logging.DEBUG)

    LOG.debug(parser)
    LOG.debug(arguments)

    if arguments.action == "help" or (arguments.action is None and not arguments.i):
        parser.print_help()
        exit()

    if arguments.action == "usage":
        parser.print_usage()
        exit()

    configfile = os.path.join(appdir, '.ptp.conf')
    if os.path.exists(configfile):
        config = parse_config(configfile)
    else:
        config = parse_env()

    ptpobj = ptp.PTP(config.get('ptp', {}).get('ApiUser'), config.get('ptp', {}).get('ApiKey'), appdir, logger=LOG)

    try:
        perform_actions(ptpobj, arguments, parser=parser)
    except ConnectionError:
        LOG.critical("Unable to connect to PTP to perform your request. Please try again later!")
Example #3
0
def perform_actions(PTPClient, args, parser=None):
    if args.i:
      print("-- PTP Interactive Mode --")
      while True:
        inputs = input("> ").lower()
        cmd = inputs.split(' ')[0]
        args = inputs.split(' ')[1:]
        if cmd in ["quit", "q"]:
          print("-- Exited --")
          return
        elif cmd == "help":
          parser.print_help()
        elif cmd == "usage":
          parser.print_usage()
        elif len(list(filter(lambda x: cmd in [x.get('name'), x.get('abbrev')], PTPClient.IMPLEMENTED))) == 0:
          LOG.critical("Invalid command '{}'.".format(cmd))
        else:
          newparser = parse_arguments(COMMANDS, prog="")
          newargs = newparser.parse_args([cmd] + args)
          perform_actions(PTPClient, newargs)

    else:
        msg = ptp.parse_ptp(PTPClient, args, returnJson=args.json)
        if args.json:
            print(json.dumps(msg, indent=2))
        else:
            print(msg)
Example #4
0
        return list(map(lambda s: self._getSongData(s), data['items']))

    def __repr__(self):
        connected_user = self.getCurrentUser()
        user = connected_user.get('display_name', connected_user.get('error'))
        status = connected_user.get('status')
        profile = connected_user.get('images', []).pop().get('url')

        showImage(profile)

        return '<Spotify (\'{}\' - {})>'.format(user, status)


if __name__ == "__main__":
    parser = argparsejson.parse_arguments(os.path.join(SCRIPT_DIR,
                                                       "commands.json"),
                                          prog=__file__)
    args = parser.parse_args()

    if args.verbose:
        VERBOSE_STDOUT = sys.stdout
    else:
        VERBOSE_STDOUT = open(os.devnull, 'w')

    print(args, file=VERBOSE_STDOUT, flush=True)

    if args.mode is None:
        parser.print_help()
    elif args.mode == 'setup':
        if args.clientid:
            clientid = args.clientid
Example #5
0
def validate():
    return argparsejson.parse_arguments("example_commands.json")