-
Notifications
You must be signed in to change notification settings - Fork 16
/
toolkits.py
executable file
·211 lines (176 loc) · 6.07 KB
/
toolkits.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from termcolor import colored
import os
import socket
import sys
import operator
def save_solution(save_name, solution):
timestr = time.strftime("%Y%m%d-%H%M%S")
document_name = '/root/Documents/wmv_to_mp4_converter/Chapter_14_15/solutions/%s_%s.csv' % (save_name, timestr)
w = open(document_name,'a+')
w.write(solution + '\n')
string = "Your solution is saved as: %s" % document_name
print yellow(string)
w.close()
return
# timestr = time.strftime("%Y%m%d-%H%M%S")
def red(string):
string = colored(string,'red',attrs=['bold'])
return string
def green(string):
string = colored(string,'green',attrs=['bold'])
return string
def yellow(string):
string = colored(string,'yellow',attrs=['bold'])
return string
def cyan(string):
string = colored(string,'cyan',attrs=['bold'])
return string
def go_back_main_menu_module():
os.system('python /root/Documents/wmv_to_mp4_converter/main.py')
return
# timestr = time.strftime("%Y%m%d-%H%M%S")
return
def open_in_new_window(command):
command = str(command)
cmd_str = "gnome-terminal -e 'bash -c \"{0}; exec bash\"'".format(
command
)
os.system(cmd_str)
# os.system("gnome-terminal -e 'bash -c \"{0}; exec bash\"'").format(
# command
# )
return
def video_converter(wordlist):
import socket
import StringIO
import operator
import os
import sys
sys.path.append("/root/Documents/wmv_to_mp4_converter")
import toolkits
# 1:
list_of_strings = "{0}".format(
str(wordlist)
)
r = open(list_of_strings,'r')
# line = r.readline()
row_number = 1
r = open(list_of_strings,'a+')
with open(list_of_strings,'a+') as r:
line = r.readline()
sentence = str(line.strip())
row_number = 1
for sentence in r:
if sentence != "":
try:
sentence = sentence.replace('(','\(').replace(')','\)')
converted_filename = sentence.replace('.wmv','.mp4')
# converted_filename = """{0}.mp4
# """.format(str(sentence))
cmd_str = "ffmpeg -i {0} {1}".format(
str(sentence.strip()),
str(converted_filename.strip())
)
# cmd_str_one = "ffmpeg -i {0}".format(str(sentence))
# cmd_str_two = " {0}".format(str(converted_filename))
# cmd_str = cmd_str_one + cmd_str_two
print yellow(cmd_str)
os.system(cmd_str)
except:
print yellow("All files converted")
def list_writer(wordlist):
def open_all_lists():
os.chdir('/root/Desktop') # Changes directory to where the generated lists are created
open_in_new_window('leafpad elif_list')
open_in_new_window('leafpad dictionary_scripts')
open_in_new_window('leafpad defined_functions')
open_in_new_window('leafpad UI_list')
return
import socket
import StringIO
import operator
import os
import sys
sys.path.append("/root/Documents/wmv_to_mp4_converter")
import toolkits
# 1:
list_of_strings = "{0}".format(
str(wordlist)
)
os.chdir("/root/Desktop")
os.system("echo '' > UI_list")
os.system("echo '' > elif_list")
os.system("echo '' > defined_functions")
os.system("echo '' > dictionary_scripts")
r = open(list_of_strings,'r')
# line = r.readline()
row_number = 1
r = open(list_of_strings,'a+')
with open(list_of_strings,'a+') as r:
line = r.readline()
sentence = str(line)
row_number = 1
for sentence in r:
if sentence != "":
row_string = """# {0}: """.format(
str(row_number)
)
sentence = sentence.replace("./",'')
sentence = sentence.strip()
ui_sentence = row_string + sentence
w = open("./UI_list","a+")
w.write(ui_sentence + '\n')
w.close()
row_string = """elif opt_choice == {0}: """.format(
str(row_number)
)
elif_sentence = row_string + '\n'
function_string = sentence + "()"
function_string = "\t" + function_string + "\n"
w = open("./elif_list","a+")
w.write(elif_sentence)
w.write(function_string)
w.close()
function_define_string = "def " + sentence + "():\n"
return_string = "\treturn\n"
w = open("./defined_functions","a+")
w.write(function_define_string)
w.write(return_string)
w.close()
dictionary_scripts = """{0}: "{1}",""".format(
str(row_number),
sentence
)
dictionary_scripts = dictionary_scripts + '\n'
w = open("./dictionary_scripts","a+")
w.write(dictionary_scripts)
w.close()
row_number = row_number + 1
open_all_lists()
def write_elif_list():
os.chdir("/root/Desktop")
r = open(list_of_strings,'r+b')
read_r = r.read()
buf = StringIO.StringIO(read_r)
row_number = 1
while True:
line = buf.readlines().strip()
if line != '':
row_string = """elif opt_choice == {0}: """.format(
str(row_number)
)
sentence = sentence.replace("./",'').replace(".nse",'')
sentence = row_string + sentence
row_number = row_number + 1
w = open("./elif_list","a+")
w.write(sentence + '\n')
w.close()
else:
print "WRITING COMPLETE"
# exit(0)
open_all_lists()
return
def main():
write_UI_list()
return
return