forked from holland-backup/holland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tomsay.py
executable file
·68 lines (55 loc) · 1.69 KB
/
tomsay.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
#! /usr/bin/python
import sys
tom = """ \ _____
\ / \\
\ | (o|o) |
\ | _\ |
| '---' |
\_____/
_\___ ___| |____
|_/\ / '-' \\
\\ \\| . NASA . |
\ / | |
\ /| | |
|_______|_/
| |_\\
| .-. |
| | | |
'._| |_.'
/__| |__\\
"""
MSG_WIDTH = 40
def split_lines(words):
line = 0
msg_list = ['']
for word in words:
line_len = len(msg_list[line])
if line_len > MSG_WIDTH:
msg_list.append('')
line = line + 1
msg_list[line] = ' '.join((msg_list[line], word)).strip()
return msg_list
def add_spaces(length, string):
return string + (' ' * (length - len(string)))
def build_bubble(msg):
lines = split_lines(msg)
longest_line = 0
for line in lines:
if len(line) > longest_line:
longest_line = len(line)
s = [' ' + ('_'*longest_line) + '_' + ' ']
for line in lines:
if line == lines[0]:
s.append("/ " + add_spaces(longest_line, line) + " \\")
elif line == lines[-1]:
s.append("\\ " + add_spaces(longest_line, line) + " /")
else:
s.append("| " + add_spaces(longest_line, line) + " |")
s.append(' ' + ('-'*longest_line) + '-' + ' ')
return '\n'.join(s)
def main():
msg = sys.argv[1:]
bubble = build_bubble(msg)
sys.stdout.write(bubble + '\n' + tom + '\n\n')
if __name__ == "__main__":
main()