Tuesday, June 28, 2016

Python's CowSay - Cowpy

It is late and has been a long day (like when I write this post now), and you need some geeky comedy relief. In comes Cowpy. According to Wikipedia:

cowsay is a program which generates ASCII pictures of a cow with a message.[2] It can also generate pictures using pre-made images of other animals, such as Tux the Penguin, the Linux mascot. It is written in Perl. There is also a related program called cowthink, with cows with thought bubbles rather than speech bubbles. .cow files for cowsay exist which are able to produce different variants of "cows", with different kinds of "eyes", and so forth.[3] It is sometimes used on IRC, desktop screenshots, and in software documentation. It is more or less a joke within hacker culture, but has been around long enough that its use is rather widespread. In 2007 it was highlighted as a Debian package of the day.

Check out the GitHub repository:
https://github.com/jeffbuttars/cowpy

One of the YouTube demo:
https://www.youtube.com/watch?v=RnfXIbMuJh0

- Sample Result (steps below):

$ cowpy -c beavis "I like Networking"
 ___________________
< I like Networking >
 -------------------
   \         __------~~-,
    \      ,'            ,
          /               \
         /                :
        |                  '
        |                  |
        |                  |
         |   _--           |
         _| =-.     .-.   ||
         o|/o/       _.   |
         /  ~          \ |
       (____\@)  ___~    |
          |_===~~~.`    |
       _______.--~     |
       \________       |
                \      |
              __/-___-- -__
             /            _ \
(venv) echou-a10:tmp echou$


1. Step 1. I use Python 3's built in venv module for virtual environment to install:

echou:tmp echou$ python3 -m venv venv
echou:tmp echou$ source venv/bin/activate

(venv) echou:tmp echou$ pip3 install cowpy
Collecting cowpy
  Downloading cowpy-1.0.1.tar.gz
Installing collected packages: cowpy
  Running setup.py install for cowpy
Successfully installed cowpy-1.0.1
You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

2. Let the fun begins:

(venv) echou:tmp echou$ cowpy
 ____________________________________
< Cowsay | cowpy. Please seek --help >
 ------------------------------------
     \   ^__^
      \  (oo)\_______
         (__)\       )\/\
           ||----w |
           ||     ||

(venv) echou:tmp echou$ echo "Network Engineering" | cowpy
 _____________________
< Network Engineering >
 ---------------------
     \   ^__^
      \  (oo)\_______
         (__)\       )\/\
           ||----w |
           ||     ||

(venv) echou:tmp echou$

(venv) echou:tmp echou$ cowpy "Network Engineering is Cool"
 _____________________________
< Network Engineering is Cool >
 -----------------------------
     \   ^__^
      \  (oo)\_______
         (__)\       )\/\
           ||----w |
           ||     ||

(venv) echou:tmp echou$ cowpy -c ghostbusters "I like Networking"
 ___________________
< I like Networking >
 -------------------
          \
           \
            \          __---__
                    _-       /--______
               __--( /     \ )XXXXXXXXXXX\v.
             .-XXX(   O   O  )XXXXXXXXXXXXXXX-
            /XXX(       U     )        XXXXXXX\
          /XXXXX(              )--_  XXXXXXXXXXX\
         /XXXXX/ (      O     )   XXXXXX   \XXXXX\
         XXXXX/   /            XXXXXX   \__ \XXXXX
         XXXXXX__/          XXXXXX         \__---->
 ---___  XXX__/          XXXXXX      \__         /
   \-  --__/   ___/\  XXXXXX            /  ___--/=
    \-\    ___/    XXXXXX              '--- XXXXXX
       \-\/XXX\ XXXXXX                      /XXXXX
         \XXXXXXXXX   \                    /XXXXX/
          \XXXXXX      >                 _/XXXXX/
            \XXXXX--__/              __-- XXXX/
             -XXXXXXXX---------------  XXXXXX-
                \XXXXXXXXXXXXXXXXXXXXXXXXXX/
                  ""VXXXXXXXXXXXXXXXXXXV""

(venv) echou-a10:tmp echou$

3. Great! So how do I add the images I want?

     Step 1. Find an online image, such as this Targaryen sigil I found online:



     Step 2. Use this site to convert the image to ascii art
     Step 3. Instantiate your own class like below


    Step 4. Enjoy your own Cowpy art!



Check out the GitHub link for all the options.

Happy Coding!





2 comments: