<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">Hello honored listmembers,<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>attached (at the end of mail body) a first PREALPHA ALPHA draft scriptlet to retrieve and play the sound file of wiktionary for a given word.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Any feedback appreciated if I am on the right track or going in total wrong direction<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>PRECONDITIONS at this moment:<br>
mplayer installed<br>
mwclient python library downloaded and installed (either in system or in same directory as the script)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>WHY ?<br>
mplayer is just a temporary workaround as the Python QT4 bindings on ubuntu (and maybe on others too) are not bundling the Phonon package --- Need to clarify why !<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>mwclient is a MIT licensed pacakge that supports requesting info from mediawiki sites. This software allows easily to retrieve the ogg files and reduces the code base for the plugin dramatically :O)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>TODO<br>
o integrate with Phonon to get rid of external app<br>
o integrate with Parley API<br>
o make it configurable based on config file<br>
o support also subcategories (de includes de, de-at, de-ch, .....; en includes en-us, en-gb,.....)<br>
o error handling in case there is no such file<br>
o polishing for a first alpha release<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>USAGE<br>
python script.py word twodigit-langcode<br>
example:<br>
python script.py introduce en<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>SCRIPT<br>
-------------------------------<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>import mwclient<br>
import sys<br>
import os<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>lang = sys.argv[2]<br>
word = sys.argv[1] <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>wikilang = ''<br>
wikilangcode = ''<br>
if (string.lower(lang[:2]) == 'en'): <br>
  wikilang = 'English'<br>
  wikilangcode = 'En-us'<br>
if (string.lower(lang[:2]) == 'fr'): wikilang = 'French'<br>
if (string.lower(lang[:2]) == 'de'): <br>
  wikilang = 'German'<br>
  wikilangcode = 'De'<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>commons = mwclient.Site('commons.wikimedia.org')<br>
image = commons.Images[wikilangcode + '-' + word + '.ogg']<br>
print 'Image', image.name.encode('utf-8')<br>
filename = u"/tmp/%s" % image.name[5:]<br>
saveas = open(filename,'w')<br>
remote = image.download()<br>
saveas.write(remote.read())<br>
saveas.close()<br>
os.execlp('mplayer', 'mplayer', filename)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p></body></html>