EvilZone
Programming and Scripting => Scripting Languages => Topic started by: Deque 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:
(http://s1.directupload.net/images/130518/2sxoxytn.png) (http://www.directupload.net)
Or this:
(http://s1.directupload.net/images/130518/3dzysp5f.png) (http://www.directupload.net)
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)
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)
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.
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])
-
Heh, that's actually a pretty nifty use for cowsay.
-
Cool one. I have written a similar thing tho:
http://evilzone.org/evilzone-releases/(c)-evilfortune/
-
Cool one. I have written a similar thing tho:
http://evilzone.org/evilzone-releases/(c)-evilfortune/ (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
-
I love this, modified it to my liking though, added random .cow selection.
-
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).