以前经常看到互联网大佬的Linux shell脚本启动的时候显示一副炫酷的字符画面,逼格瞬间提升一个档次,按说字符拼画也不是什么难事,只要有时间、有耐心(然鹅大部分人这两样都没有)。
网上流传着一个很老的库cawsay牛说。cowsay是一个生成ASCII图片的程序,显示一头牛的消息。它也可以使用预先制作的图像,以生成其他动物的图片,如Linux的吉祥物企鹅。由于它是用Perl编写的,它也适用于其他系统,如微软的Windows。
cawsay的风格看起来是酱婶儿的
$ fortune | cowsay
________________________________________
/ You have Egyptian flu: you're going to \
\ be a mummy. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
这里要安利的是python的cawsay版本,代码在这里:
https://github.com/jeffbuttars/cowpy
使用很简单,一键引入python程序,执行即可,效果与Linux下的cawsay一样样的
安装
pip install cowpy
使用
#!/usr/bin/env python
# encoding: utf-8
from cowpy import cow
# Create a Cow
cheese = cow.Moose()
# Get a cowsay message by milking the cow
msg = cheese.milk("My witty mesage")
# do something with the message
print(msg)
# Create a Cow with a thought bubble
cheese = cow.Moose(thoughts=True)
msg = cheese.milk("My witty mesage, with thought")
print(msg)
# Create a Cow with a tongue
cheese = cow.Moose(tongue=True)
msg = cheese.milk("My witty mesage, with tongue")
print(msg)
# Create a Cow with dead eyes
cheese = cow.Moose(eyes='dead')
msg = cheese.milk("my witty mesage, i'm dead")
print(msg)
# Get a cow by name
cow_cls = cow.get_cow('moose')
cheese = cow_cls()
msg = cheese.milk("Cow by name is moose")
print(msg)
# Create a Cow with a thought bubble, a tongue, and dead eyes
cheese = cow.Moose(thoughts=True, tongue=True, eyes='dead')
msg = cheese.milk("My witty mesage with several attributes")
print(msg)
这个函数可以随机抽一个风格的牛生成图像:
# Create a random cow with a message
msg = cow.milk_random_cow("A random message for fun")
print(msg)
这个方法可以列举所有备选图像:
# all the eye options
eye_options = cow.eye_options()
print(eye_options)
# all the cowacter options
cow_options = cow.cow_options()
print(cow_options)
也可以引入fortune
的语料库随机抽文字给cawsay,如此简单两步就可以让你的python脚本瞬间拥有大佬内味儿了。
__________________________________________________________________
/ Do not argue with an idiot. \
\ He will drag you down to his level and beat you with experience. /
------------------------------------------------------------------
o
o
_ _
| \__/| .~ ~.
/$$ `./ .'
{o__, \ {
/ . . ) \
`-` '-' \ }
.( _( )_.'
'---.~_ _ _|