以前經(jīng)常看到互聯(lián)網(wǎng)大佬的Linux shell腳本啟動的時候顯示一副炫酷的字符畫面,逼格瞬間提升一個檔次,按說字符拼畫也不是什么難事,只要有時間、有耐心(然鵝大部分人這兩樣都沒有)。
網(wǎng)上流傳著一個很老的庫cawsay牛說。cowsay是一個生成ASCII圖片的程序,顯示一頭牛的消息。它也可以使用預(yù)先制作的圖像,以生成其他動物的圖片,如Linux的吉祥物企鵝。由于它是用Perl編寫的,它也適用于其他系統(tǒng),如微軟的Windows。
cawsay的風(fēng)格看起來是醬嬸兒的
$ fortune | cowsay
________________________________________
/ You have Egyptian flu: you're going to \
\ be a mummy. /
----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
這里要安利的是python的cawsay版本,代碼在這里:
https://github.com/jeffbuttars/cowpy
使用很簡單,一鍵引入python程序,執(zhí)行即可,效果與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)
這個函數(shù)可以隨機抽一個風(fēng)格的牛生成圖像:
# 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腳本瞬間擁有大佬內(nèi)味兒了。
__________________________________________________________________
/ Do not argue with an idiot. \
\ He will drag you down to his level and beat you with experience. /
------------------------------------------------------------------
o
o
_ _
| \__/| .~ ~.
/$$ `./ .'
{o__, \ {
/ . . ) \
`-` '-' \ }
.( _( )_.'
'---.~_ _ _|