-
Notifications
You must be signed in to change notification settings - Fork 0
/
fortune.py
71 lines (66 loc) · 1.52 KB
/
fortune.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import os
import subprocess
def fortune(args):
try:
args = args.split( )
cmd = []
cmd.append('/usr/games/fortune')
for arg in args:
if arg.startswith("-"):
arg = arg.replace('w', '')
arg = arg.replace('m', '')
arg = arg.replace('i', '')
arg = arg.replace('n', '')
if len(arg) == 1:
arg = "-a"
cmd.append(arg)
p = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return p
except subprocess.CalledProcessError as error:
print error
return "That was not a valid option for fortune."
#return p
def fortuneHelp():
return """print a random, hopefully interesting, adage
usage: '/fortune <args> fileName'
allowed flags are: -acefilosu
please note:
[-n length] and [ -m pattern]
DO NOT WORK"""
def cowsay(args):
try:
#print args
cmd = []
cmd.append('/usr/games/cowsay')
cmd.append('-W 25')
for arg in args:
arg = arg.replace("-", "")
cmd.append(arg)
p = subprocess.check_output(cmd)
return p
except subprocess.CalledProcessError as error:
#print error
return "That was not a valid option for cowsay."
def madcow(args):
try:
#print args
cmd = []
cmd.append('/usr/games/cowsay')
cmd.append('-d')
cmd.append('-W 25')
for arg in args:
cmd.append(arg)
p = subprocess.check_output(cmd)
#print p
return p
except subprocess.CalledProcessError as error:
print error
return "That was not a valid option for fortune."
def main():
p = fortune('-o')
#print p
p = cowsay(([p]))
print p
if __name__ == '__main__':
main()