-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser.py
executable file
·111 lines (82 loc) · 2.38 KB
/
parser.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
import os
import sys
import subprocess
def parseCharacters(cast):
line = cast.readline();
chars = {}
comps = []
voices = []
while(line):
char,comp,voice = line.split(',')
voice = voice.strip()
chars[char] = {'computer':comp, 'voice':voice };
if voice not in voices:
voices.append(voice)
if comp not in comps:
comps.append(comp)
line = cast.readline();
chars["All"] = {};
return chars,comps,voices;
def getCurrentSpeaker(line):
current = line.strip("$");
current = current.strip("\n");
current = current.strip(":");
return current
def call(command,fnull):
result = subprocess.call(command, shell = True, stdout = fnull, stderr = fnull);
return
def ssh(comp):
return "ssh " + str(comp) + " -i ~/.ssh/ix_dsa"
def generateCommand(line,character,volume):
command = "\"osascript -e \\\"set volume " + str(volume) + "\\\" > /dev/null; say \\\"" + line + "\\\" -v " + character["voice"] +"\"";
return command
def main():
#scene = open("temp-script.txt",'r');
scene = open("scene-i-i.txt",'r');
cast = open("dramatis-personae.txt",'r');
fnull = open(os.devnull, 'w');
debug = True;
current = "ANNOUNCER"
dirpath = "/home/users/ehamovit/Projects/hamlet/"
count = 0;
volume = 7;
cutoff = 90;
# CHARACTERS
characters,computers,voices = parseCharacters(cast);
# PRE-SCENE SETUP
print "Setting volumes to " + str(volume) + ":"
for comp in computers:
command = ssh(comp) + " \"osascript -e \\\"set volume " + str(volume) + "\\\" > /dev/null \""
print " " + str(comp) + "...",
call(command,fnull)
print "done"
# SCENE
print("BEGINNING PLAY");
line = scene.readline();
while(line):
# Ignore empty lines
if(line == "" or line.strip() == ""):
line = scene.readline()
count += 1
continue
# Process real line
if(line[0]=="$"):
current = getCurrentSpeaker(line);
if(debug):
print current + "@" + characters[current]["computer"] + ":";
else:
line = line.strip();
command = ssh(characters[current]["computer"]) + " " + generateCommand(line,characters[current],volume)
print command
if(debug):
print " " + line
call(command,fnull);
line = scene.readline();
count += 1;
sys.stdout.flush()
scene.close()
fnull.close()
cast.close()
if __name__ == "__main__":
main();