-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathask_random.py
50 lines (43 loc) · 1.37 KB
/
ask_random.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
#!/usr/bin/env python
import os, sys, random
def main():
print "YC Interview Practice - by @shauvik"
print "==================================="
questions = []
for file in os.listdir("."):
if file.endswith(".txt"):
for line in open(file):
if(not line.startswith('Section')):
questions.append(line)
print "You will be asked questions one by one."
print "Adjust font-size using Ctrl+/-"
print "Press any key to proceed through questions... (Ctrl X to quit)"
wait_key()
while(True):
line = random.choice(questions)
os.system('clear')
os.system('echo '+line)
os.system('say -r 400 '+line)
wait_key()
def wait_key():
''' Wait for a key press on the console and return it. '''
result = None
if os.name == 'nt':
import msvcrt
result = msvcrt.getch()
else:
import termios
fd = sys.stdin.fileno()
oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)
try:
result = sys.stdin.read(1)
except IOError:
pass
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
return result
if __name__ == '__main__':
main()