Zamber
By: a guest | Oct 26th, 2007 | Syntax:
Python | Size: 2.02 KB | Hits: 204 | Expires: Never
#!/usr/bin/python
# -*- coding: utf-8 -*-
#imports
import os
import sys
import subprocess
from urllib import urlencode
def ivnot():
# Create output log file
outFile = os.path.join(os.curdir, "output.log")
outptr = file(outFile, "w")
# Create error log file
errFile = os.path.join(os.curdir, "error.log")
errptr = file(errFile, "w")
# pl chars not recognized!
# leave the b on the ond cause the site reader cuts the last word ;/
text = "I can read this fluently for you! b"
url_text = urlencode({'tresc':text})
# Voices:
# Jennifer | eng fem
# Ewa | pol fem
# Jacek | pol mal
# Carmen+%28drugie+wydanie%29 | hun fem
# insert after glos= in line 3 of cmd
cmd = [\
'curl '\
'-d '\
'"' + url_text + '&glos=Jennifer&IVONA_odczytaj=%20%20%20Odczytaj20%20" '\
'http://www.ivo.pl/ivonaonline.html '\
'| '\
'grep '\
'-e '\
'http:\/\/www.ivo.pl\/media\/ivonaonline\/[a-Z0-9]*.mp3 '\
'-o '\
'| '\
'tail '\
'-n '\
'1'\
]
#command = str('curl -d "' + url_tresc + '&glos=Ewa&IVONA_odczytaj=%20%20%20Odczytaj20%20" http://www.ivo.pl/ivonaonline.html | grep -e http:\/\/www.ivo.pl\/media\/ivonaonline\/[a-Z0-9]*.mp3 -o | tail -n 1')
retval = subprocess.call(cmd, 0, None, None, outptr, errptr, None, False, True)
# Close log handles
errptr.close()
outptr.close()
# Check the process exit code
if not retval == 0:
errptr = file(errFile, "r")
errData = errptr.read()
errptr.close()
raise Exception("Error executing command: " + repr(errData))
# mplayer
outptr = file(outFile, "r")
outData = outptr.read()
outptr.close()
play = "mplayer " + str(outData.replace("\n",""))
os.system(play)
if __name__ == '__main__':
ivnot()