Posted by Zamber on Fri 26 Oct 12:57
report abuse | download | new post
- #!/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()
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.