diff --git a/nicethings b/nicethings index afcd4e9..20cc77f 100755 --- a/nicethings +++ b/nicethings @@ -12,10 +12,12 @@ bottom_line = "\n-----------------------------------------" messages = {'list_created': "{} created, try your command again and it should work :)".format(the_list), 'list_empty': "sorry, there's nothing in {}\nTry adding something to the list by typing:\n{} \"your message here\"".format(the_list, program_name), - 'args_too_many': "Sorry, I only accept one argument.\nTry using:\n{} \"your message here\"".format(program_name), - 'input_null': "Sorry, I couldn't find any input.\n\nTry using:\n{} \"your message here\"".format(program_name), - 'item_added': "You have added the following to the list:\n", - 'try_again': "sorry, I didn't get that, try typing y or n:", + 'args_too_many': "Sorry, i only accept one argument.\ntry using:\n{} \"your message here\"".format(program_name), + 'input_null': "sorry, i couldn't find any input.\n\niry using:\n{} \"your message here\"".format(program_name), + 'item_added': "you have added the following to the list:\n", + 'try_again': "sorry, i didn't get that, try typing y or n:", + 'bye': "bye bye", + 'too_many_args': "sorry, i only accept one argument.\ntry using:\n{} \"your message here\"".format(program_name), 'file_not_found': "{} doesn't exist\ndo you want me to make a {} file right now? (y/n)".format(the_list, the_list)} def write_to_file(list_file, content): @@ -36,36 +38,36 @@ def show_random_line(list_file): else: print(random.choice(list(open(the_list, 'r'))).rstrip('\n')) -def add_to_list(): - write_to_file(the_list, sys.argv[1] + "\n") - print(top_line + messages['item_added'] + sys.argv[1] + bottom_line) +def add_to_list(args): + write_to_file(the_list, args + "\n") + print(top_line + messages['item_added'] + args + bottom_line) -def hangle_args(): - if len(sys.argv) <= 1: +def hangle_args(args): + if len(args) <= 1: show_random_line(the_list) - elif len(sys.argv) > 2: - too_many_args() - elif sys.argv[1].isspace() == True or sys.argv[1] == "": + elif len(args) > 2: + print(messages['too_many_args']) + elif args[1].isspace() == True or args[1] == "": print(messages['input_null']) else: - add_to_list() + add_to_list(args[1]) def prompt_file_creation(): userchoice = input() if userchoice == "y": create_file(the_list) elif userchoice == "n": - print("bye bye") + print(messages['bye']) else: print(messages['try_again']) prompt_file_creation() -def main(): +def main(args): if os.path.exists(the_list) == True: - hangle_args() + hangle_args(args) else: print(messages['file_not_found']) prompt_file_creation() if __name__ == '__main__': - main() + main(sys.argv)