-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm8y_ball.py
82 lines (72 loc) · 1.72 KB
/
m8y_ball.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
72
73
74
75
76
77
78
79
80
81
82
from random import choice
import argparse
from json import loads
from glob import glob
parser = argparse.ArgumentParser(description='The classical magic 8-ball will now answer your questions.')
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument('input', nargs='?', help='predefined type')
group.add_argument('-i', type=argparse.FileType('r'), help='input file (txt)')
group.add_argument('-l', '--list', action='store_true', help='list all predefined types')
args = parser.parse_args()
positive = [
'It is certain',
'It is decidedly so',
'Without a doubt',
'Yes definitely',
'You may rely on it',
'As I see it, yes',
'Most likely',
'Outlook good',
'Yes',
'Signs point to yes'
]
ncommit = [
'Reply hazy try again',
'Ask again later',
'Better not tell you now',
'Cannot predict now',
'Concentrate and ask again'
]
negativ = [
'Don\'t count on it',
'My reply is no',
'My sources say no',
'Outlook not so good',
'Very doubtful'
]
answers = [positive, ncommit, negativ]
def listt():
pre = glob('answer_*')
pra = []
for x in pre:
pra.append(x.split('_',1)[1])
return pra
def answt(pre):
alist = []
with open('answer_' + pre) as file:
for line in file:
alist.append(line.rstrip())
answer = choice(alist)
return answer
def answf(file):
alist = []
for line in file:
alist.append(line.rstrip())
answer = choice(alist)
return answer
def answer():
alist = []
mood = choice(answers)
answer = choice(mood)
return answer
if __name__ == "__main__":
if args.list:
for x in listt():
print(x)
if args.input is not None:
print(answt(args.input))
if args.i is not None:
print(answf(args.i))
if not args.list and args.input is None and args.i is None:
answer = answer()
print(answer)