From 31f42b97467121b173bbc958822cc03000dac69d Mon Sep 17 00:00:00 2001 From: Jake Zaia Date: Fri, 18 Oct 2019 17:16:17 -0400 Subject: [PATCH] Finish code needed to close issue #14 --- src/batsay.py | 47 -------------------- src/quote.py | 22 +++++++--- src/roosay.py | 119 -------------------------------------------------- 3 files changed, 16 insertions(+), 172 deletions(-) delete mode 100644 src/batsay.py delete mode 100644 src/roosay.py diff --git a/src/batsay.py b/src/batsay.py deleted file mode 100644 index 0c034e4..0000000 --- a/src/batsay.py +++ /dev/null @@ -1,47 +0,0 @@ -import roosay -import sys - -def main(): - """ - checks for command line arguments - :return: None - """ - message = "" - for i in range(1, len(sys.argv)): - if len(message) > 0: - message += " " - message += sys.argv[i] - - if len(message) == 0: - for line in sys.stdin: - message+= line - - message = " ".join(message.split()) - batsay(message) - -def batsay(message): - """ - prints message through roosay print - message function the prints bat. - :param message: the message to print - :return: None - """ - roosay.print_message(message) - print_bat() - -def print_bat(): - """ - prints bat ascii - :return: None - """ - print(" \ ") - print(" /\ \ /\ ") - print(" / \\'._ (\_/) _.'/ \ ") - print(" |.''._'--(o.o)--'_.''.|") - print(' \_ / `;=/ " \=;` \ _/ ') - print(" `\__| \___/ |__/` ") - print(" \(_|_)/ ") - print(' " ` " ') - -if __name__ == '__main__': - main() diff --git a/src/quote.py b/src/quote.py index 6911f57..934fe63 100644 --- a/src/quote.py +++ b/src/quote.py @@ -14,7 +14,6 @@ import glob from utils import module from utils import print_message_bubble -import roosay import configuration @@ -22,20 +21,28 @@ import configuration INPUT_FILE = configuration.get_config()["quotes"] """Pulls a list of the ascii art file names""" -BASE_FILE = os.path.dirname(__file__) +BASE_FILE = os.path.dirname(os.path.realpath(__file__)) ASCII_ART = glob.glob(BASE_FILE + "/asciiArt/*.txt") -def print_message(message): +def print_message(message, ascii_file = None): """ Prints a dialog box with a message in it with an ascii animal below it :param message: a quote to print + :param ascii_file: the file location of the ascii art speaking the message :return: NA """ print_message_bubble.print_message(message) - print(module.input_file_with_new_line( - ASCII_ART[random.randint(0,(len(ASCII_ART) -1))])) + if ascii_file != None: + filepath = '/'.join(INPUT_FILE.split('/')[:-1]) + filepath += "/asciiArt/" + ascii_file + f = open(filepath, 'r') + print(f.read()) + f.close() + else: + print(module.input_file_with_new_line( + ASCII_ART[random.randint(0,(len(ASCII_ART) -1))])) def print_usage(): @@ -78,6 +85,9 @@ def main(): add_quote() else: print("You forgot to enter a quote.") + elif sys.argv[1][:2] == "--": + quotes = module.input_file(INPUT_FILE) + print_message(quotes[random.randint(0,(len(quotes) -1))], ascii_file=sys.argv[1][2:]+'.txt') else: print_usage() else: @@ -96,4 +106,4 @@ if __name__ == '__main__': try: main() except KeyboardInterrupt: - exit() \ No newline at end of file + exit() diff --git a/src/roosay.py b/src/roosay.py deleted file mode 100644 index de8edde..0000000 --- a/src/roosay.py +++ /dev/null @@ -1,119 +0,0 @@ -""" -Python script that prints an ascii roo with a message above it -Jeffery Russell -10-8-17 -""" - -import sys - -from utils import print_message_bubble - - -def main(): - """ - checks for command line arguments - :return: None - """ - message = "" - for i in range(1, len(sys.argv)): - if len(message) > 0: - message += " " - message += sys.argv[i] - - if len(message) == 0: - for line in sys.stdin: - message+= line - - message = " ".join(message.split()) - roo_say(message) - - -def roo_say(message): - """ - Method which prints an ascii roo with a message above it - :param message: the message to print - :return: none - """ - print_message_bubble.print_message(message) - #print_message(message) - print_roo() - - -def print_message(message): - """ - Prints the message above Roo - :param message: the message to print - :return: None - """ - print_list, max_len = convert_to_list(message) - - if len(print_list) > 0: - "Print top" - print(" " + "-" * (2 + max_len)) - - "print middle" - if len(print_list) == 1: - print("< " + print_list[0] + " >") - else: - for i in range(0, len(print_list)): - if i == 0: - print("/ " + print_list[i] - + " " * (max_len - len(print_list[i])) +" \\") - elif i == len(print_list) -1: - print("\ " + print_list[i] - + " " * (max_len - len(print_list[i])) + " /") - else: - print("| " + print_list[i] - + " " * (max_len - len(print_list[i])) + " |") - "print bottom" - print(" " + "-" * (max_len + 2)) - else: - print("Please pass in a message parameter") - - -def convert_to_list(message): - """ - Converts the message into string lines which are - less than 35 characters - easier for printing - :param message: the string message - :return: the list of the string lines and the length of the longest line - """ - temp_build = "" - temp_return = [] - max_len = 0 - for word in message.split(" "): - if len(temp_build) + len(word) < 35: - if len(temp_build) > 0: - temp_build += " " - temp_build += word - if max_len < len(temp_build): - max_len = len(temp_build) - else: - temp_return.append(temp_build) - temp_build = word - if len(temp_build) > 0: - temp_return.append(temp_build) - return temp_return, max_len - - -def print_roo(): - """ - prints the roo ascii - :return: None - """ - print("") - print(" \ /)/)") - print(" \ (ø.ø)") - print(" \ ( />") - print(" __/ _\ //") - print(" '~( '~ )//") - print(" _\ '}/") - print(" \"--~(/") - - -""" -If ran from command line, this will call the main which -looks for command line arguments -""" -if __name__ == '__main__': - main()