cleaned up a lot of things

cleanup
m455 2018-08-07 10:19:30 -04:00
parent a16412ee4e
commit 5e73f74d5d
1 changed files with 19 additions and 17 deletions

View File

@ -12,10 +12,12 @@ bottom_line = "\n-----------------------------------------"
messages = {'list_created': "{} created, try your command again and it should work :)".format(the_list), 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), '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), '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), '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", 'item_added': "you have added the following to the list:\n",
'try_again': "sorry, I didn't get that, try typing y or 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)} '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): def write_to_file(list_file, content):
@ -36,36 +38,36 @@ def show_random_line(list_file):
else: else:
print(random.choice(list(open(the_list, 'r'))).rstrip('\n')) print(random.choice(list(open(the_list, 'r'))).rstrip('\n'))
def add_to_list(): def add_to_list(args):
write_to_file(the_list, sys.argv[1] + "\n") write_to_file(the_list, args + "\n")
print(top_line + messages['item_added'] + sys.argv[1] + bottom_line) print(top_line + messages['item_added'] + args + bottom_line)
def hangle_args(): def hangle_args(args):
if len(sys.argv) <= 1: if len(args) <= 1:
show_random_line(the_list) show_random_line(the_list)
elif len(sys.argv) > 2: elif len(args) > 2:
too_many_args() print(messages['too_many_args'])
elif sys.argv[1].isspace() == True or sys.argv[1] == "": elif args[1].isspace() == True or args[1] == "":
print(messages['input_null']) print(messages['input_null'])
else: else:
add_to_list() add_to_list(args[1])
def prompt_file_creation(): def prompt_file_creation():
userchoice = input() userchoice = input()
if userchoice == "y": if userchoice == "y":
create_file(the_list) create_file(the_list)
elif userchoice == "n": elif userchoice == "n":
print("bye bye") print(messages['bye'])
else: else:
print(messages['try_again']) print(messages['try_again'])
prompt_file_creation() prompt_file_creation()
def main(): def main(args):
if os.path.exists(the_list) == True: if os.path.exists(the_list) == True:
hangle_args() hangle_args(args)
else: else:
print(messages['file_not_found']) print(messages['file_not_found'])
prompt_file_creation() prompt_file_creation()
if __name__ == '__main__': if __name__ == '__main__':
main() main(sys.argv)