Browse Source

Merge pull request #18 from jzaia18/master

Close issue #14
pull/23/head
Jeffery Russell 5 years ago
committed by GitHub
parent
commit
1959b82b0a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 172 deletions
  1. +0
    -47
      src/batsay.py
  2. +16
    -6
      src/quote.py
  3. +0
    -119
      src/roosay.py

+ 0
- 47
src/batsay.py View File

@ -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()

+ 16
- 6
src/quote.py View File

@ -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()
exit()

+ 0
- 119
src/roosay.py View File

@ -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()

Loading…
Cancel
Save