Author Topic: [Python] Make your terminal greet you  (Read 1630 times)

0 Members and 1 Guest are viewing this topic.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
[Python] Make your terminal greet you
« on: May 17, 2013, 10:03:42 pm »
I just wrote a simple script to realize a terminal that greets me depending on the daytime and shows a random quote. It might look like this:



Or this:



And this is how you do it:

Install cowsay and fortune

Save this as welcome.py in your home (or somewhere else). Modify it for your needs (i.e. instead of tux in the last line choose something else, like dragon, cock, snowman, elephant, milk, cow, pony, kiss, koala, gnu, skeleton, ren, moose, sheep ... (see /usr/share/cowsay/cows for the files available)

Code: (Python) [Select]
import getpass
from datetime import datetime
from subprocess import call, Popen, PIPE

user = getpass.getuser()
hour = datetime.time(datetime.now()).hour

if hour >= 22:
    str = "Sleep Well, " + user + "!"
elif hour >= 18:
    str = "Good Evening, " + user + "!"
elif hour >= 14:
    str = "Good Afternoon, " + user + "!"
elif hour >= 12:
    str = "Enjoy Your Meal, " + user + "!"
else:
    str = "Good Morning, " + user + "!"

fortune = Popen(["fortune"], stdout=PIPE).communicate()[0]

call(["cowsay", "-f", "dragon", str + "\n\n" + fortune])

Add the following line to  .bashrc (if you didn't save the .py in your home, you will have to edit the path)

Code: [Select]
python welcome.py
Now everytime you open your terminal you get an appropriate greeting and a random quote.

Alternatively you can use this randomized welcome.py (shows a random ascii art). Note the blacklist, where you can add your unwanted cows.

Code: (Python) [Select]
import getpass
import random
from datetime import datetime
from subprocess import call, Popen, PIPE
from os import listdir
from os.path import isfile, join

blacklist = ["beavis.zen", "ghostbusters", "elephant-in-snake", "unipony", "daemon", "sodomized-sheep", "eyes", "kosh", "calvin", "gnu", "kiss", "turkey", "turtle", "pony", "mutilated", "head-in"]

cowpath = "/usr/share/cowsay/cows"
cows = [ f[:-4] for f in listdir(cowpath) if isfile(join(cowpath,f)) and f.endswith(".cow") and f[:-4] not in blacklist ]

user = getpass.getuser()
hour = datetime.time(datetime.now()).hour
random_cow = random.choice(cows)
say_or_think = random.choice(["say", "think"])

if hour >= 22:
    str = "Sleep Well, " + user + "!"
elif hour >= 18:
    str = "Good Evening, " + user + "!"
elif hour >= 14:
    str = "Good Afternoon, " + user + "!"
elif hour >= 12:
    str = "Enjoy Your Meal, " + user + "!"
else:
    str = "Good Morning, " + user + "!"

fortune = Popen(["fortune"], stdout=PIPE).communicate()[0]

call(["cow" + say_or_think, "-f", random_cow, str + "\n\n" + fortune])
« Last Edit: May 18, 2013, 10:13:18 pm by Deque »

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Python] Make your terminal greet you
« Reply #1 on: May 17, 2013, 10:10:54 pm »
Heh, that's actually a pretty nifty use for cowsay.


Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: [Python] Make your terminal greet you
« Reply #2 on: May 18, 2013, 09:49:20 am »
Cool one. I have written a similar thing tho:
http://evilzone.org/evilzone-releases/(c)-evilfortune/

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: [Python] Make your terminal greet you
« Reply #3 on: May 18, 2013, 06:31:01 pm »
Cool one. I have written a similar thing tho:
http://evilzone.org/evilzone-releases/(c)-evilfortune/

Thanks for mentioning your project, because that is really good addition to my code too. I've update my code for random quotes.
<3 Kulver +1

Offline WirelessDesert

  • Knight
  • **
  • Posts: 356
  • Cookies: 10
  • I think...
    • View Profile
Re: [Python] Make your terminal greet you
« Reply #4 on: May 19, 2013, 11:38:00 am »
I love this, modified it to my liking though, added random .cow selection.
Check out my arduino project: Moving car - School project!
"I'm like current, I always take the easiest route."

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: [Python] Make your terminal greet you
« Reply #5 on: May 20, 2013, 10:56:56 am »
I love this, modified it to my liking though, added random .cow selection.

Thank you.
That's what I did too. I posted the randomized cow selection afterwards under customization.
It also calls randomly cowthink or cowsay.
I am thinking of adding a random mood too (results in different tongue and eyes).