Share Pastebin
Guest
Public paste!

Zamber

By: a guest | Oct 26th, 2007 | Syntax: Python | Size: 2.02 KB | Hits: 204 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. #imports
  4. import os
  5. import sys
  6. import subprocess
  7. from urllib import urlencode
  8.  
  9. def ivnot():
  10.  
  11.     # Create output log file
  12.     outFile = os.path.join(os.curdir, "output.log")
  13.     outptr = file(outFile, "w")
  14.     # Create error log file
  15.     errFile = os.path.join(os.curdir, "error.log")
  16.     errptr = file(errFile, "w")
  17.    
  18.     # pl chars not recognized!
  19.     # leave the b on the ond cause the site reader cuts the last word ;/
  20.     text = "I can read this fluently for you! b"
  21.     url_text = urlencode({'tresc':text})
  22.  
  23.     # Voices:
  24.     # Jennifer                     | eng fem
  25.     # Ewa                          | pol fem
  26.     # Jacek                        | pol mal
  27.     # Carmen+%28drugie+wydanie%29  | hun fem
  28.     # insert after glos= in line 3 of cmd
  29.  
  30.     cmd = [\
  31.            'curl '\
  32.            '-d '\
  33.            '"' + url_text + '&glos=Jennifer&IVONA_odczytaj=%20%20%20Odczytaj20%20" '\
  34.            'http://www.ivo.pl/ivonaonline.html '\
  35.            '| '\
  36.            'grep '\
  37.            '-e '\
  38.            'http:\/\/www.ivo.pl\/media\/ivonaonline\/[a-Z0-9]*.mp3 '\
  39.            '-o '\
  40.            '| '\
  41.            'tail '\
  42.            '-n '\
  43.            '1'\
  44.            ]
  45.  
  46.     #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')
  47.  
  48.     retval = subprocess.call(cmd, 0, None, None, outptr, errptr, None, False, True)
  49.  
  50.     # Close log handles
  51.     errptr.close()
  52.     outptr.close()
  53.  
  54.         # Check the process exit code
  55.     if not retval == 0:
  56.         errptr = file(errFile, "r")
  57.         errData = errptr.read()
  58.         errptr.close()
  59.         raise Exception("Error executing command: " + repr(errData))
  60.  
  61.     # mplayer
  62.     outptr = file(outFile, "r")
  63.     outData = outptr.read()
  64.     outptr.close()
  65.     play = "mplayer " + str(outData.replace("\n",""))
  66.     os.system(play)
  67.  
  68. if __name__ == '__main__':
  69.     ivnot()