def main(): parser = create_parser() # Parse arguments if len(sys.argv) <= 1: args = parser.parse_args(['-h']) else: args = parser.parse_args() if args.version: print(mal.__version__) sys.exit(0) # if the command is login, create credentials and exits # NOTE: if this statement is removed the `mal login` and # no credentials exists, login.create_credentials() will # be called twice! On login.get_credentials and args.func(mal, args) if args.command == 'login': login.create_credentials() sys.exit(0) # Check if authorized config = login.get_credentials() if config['config']['animation'].lower() == 'false': decorating.animated.enabled = False mal_api = MyAnimeList.login(config) if not mal_api: print(color.colorize('Invalid credentials! :(', 'red', 'bold')) print(color.colorize('Tip: Try "mal login" again :D', 'white', 'bold')) sys.exit(1) # Execute sub command args.func(mal_api, args)
def login(mal, args): """Creates login credentials so that next time the program is called it can log in right at the start without any problem.""" _login.create_credentials() sys.exit(0)