Devadutta Ghat's Blog

Day 1: cowsay alternative – kittysay

Alrighty, lets flex our AI muscle just a little today so we don’t tear our ACL when we run next. As you know from Zombieland, you gotta limber up first.

tools

ChatGPT-4

prompt

I need a python script to mimic cowsay, but I want it to print a cat.

output

#!/usr/bin/env python3
import sys
import textwrap

def create_kitty_speech(message):
    message_lines = textwrap.wrap(message, width=40)
    message_width = max(len(line) for line in message_lines)

    # Create the top border
    speech_bubble = f" {'_' * (message_width + 2)}\n"

    # Add the message lines
    for index, line in enumerate(message_lines):
        if index == 0:
            speech_bubble += f"< {line.ljust(message_width)} >\n"
        elif index == len(message_lines) - 1:
            speech_bubble += f"\\ {line.ljust(message_width)} /\n"
        else:
            speech_bubble += f"| {line.ljust(message_width)} |\n"

    # Create the bottom border
    speech_bubble += f" {'-' * (message_width + 2)}"

    return speech_bubble

def print_kitty(message):
    kitty_art = r'''
      /\_/\  
     / o o \ 
    (   "   )
    '''
    
    print(create_kitty_speech(message))
    print(kitty_art)

if __name__ == "__main__":
    message = " ".join(sys.argv[1:])
    if not message:
        print("Please provide a message to display.")
    else:
        print_kitty(message)

..and running it gives us…

 $python3 kitty.py You have come a long way my friend                                                     
 ____________________________________
< You have come a long way my friend >
 ------------------------------------
     
      /\_/\
     / o o \
    (   "   )

Good outcome for 30 Seconds of work. I feel so productive.