Name: Duncan McGreggor
Member since: 2001-11-21 22:13:44
Last Login: 2008-10-23 14:55:14
Homepage: You're looking at it.
Notes: If you would like to leave comments on the blog posts, visit the blogger version.
echo "wngvtg@twrmnf.nl" | tr a-z h-za-g(thanks for the tip, fxn !)
26 Oct 2009 (updated 27 Oct 2009 at 07:05 UTC) »
Recent Work on Various Open Source Projects
Syndicated 2009-10-26 14:16:00 (Updated 2009-10-27 06:20:50) from Duncan McGreggor
PyCon 2010 Talks Neeed!
Syndicated 2009-09-17 17:12:00 (Updated 2009-09-17 17:22:44) from Duncan McGreggor
14 Sep 2009 (updated 17 Sep 2009 at 06:03 UTC) »
txSpore: Twisted Spore
I just had a delightful weekend of coding :-) I spent the past two days porting the Spore Python API to Twisted. You can now incorporate Spore data (from static XML as well as REST requests) into your non-blocking Python applications/games!Syndicated 2009-09-14 05:05:00 (Updated 2009-09-17 05:38:20) from Duncan McGreggor
Windows Media to MP3 Conversion for Mac OS X and Linux
#!/usr/bin/python
import os
import re
import subprocess
import sys
# script configuration
if sys.platform == "darwin":
MPLAYER_PATH = os.path.join(
"/Applications/Non-Standard/Audio and Video",
"MPlayer OS X 2.app/Contents/Resources/mplayer.app/Contents/MacOS")
# lame was manually installed into /usr/bin
LAME_PATH="/usr/bin"
elif sys.platform == "linux2":
MPLAYER_PATH = "/usr/bin"
LAME_PATH="/usr/bin"
MPLAYER = os.path.join(MPLAYER_PATH, "mplayer")
LAME = os.path.join(LAME_PATH, "lame")
DUMP_FILE = "audiodump.wav"
BACKUP_DIR = "wma"
WORKING_DIR = "/tmp"
def make_audio_dump(filename):
"""
Use mplayer to dump the audio contents of the .wma files as .wav files.
"""
command = ("\"%s\" -nosound -vo null -vc dummy -af resample=44100 -aid 1 "
"-ao pcm:waveheader \"%s\"" % (MPLAYER, filename))
subprocess.call(command, shell=True)
def convert_wav_to_mp3(input, output):
"""
Use lame to convert the .wav files to .mp3 files. Remove the raw .wav file
when done.
"""
command = "\"%s\" -b 256 -h \"%s\" -o \"%s\"" % (LAME, input, output)
subprocess.call(command, shell=True)
os.unlink(input)
def convert_wma_to_mp3(wma_filename):
"""
Given a .wma filename, get a filename for the new .mp3 file based on this,
convert the original to a .wav and then that to an .mp3 file.
"""
mp3_filename = re.sub("\.wma$", ".mp3", wma_filename)
make_audio_dump(wma_filename)
convert_wav_to_mp3(DUMP_FILE, mp3_filename)
def has_wma_files(filenames):
"""
Given a list of filenames, check to see if any of them have the .wma file
extension. If so, return a true value; otherwise, a false one.
"""
for filename in filenames:
if filename.endswith(".wma"):
return True
return False
def convert_wma_files(path):
"""
Walk a given file system directory and all its child directories in order
to find .wma files. If found, convert them to .mp3 files and backup the
originals.
"""
for dir, subdirs, filenames in os.walk(path):
# we don't want to convert files that have already been converted
if os.path.basename(dir) == BACKUP_DIR:
continue
# if there's nothing to do, move on
if not has_wma_files(filenames):
continue
# define and create the backup dir, if it hasn't been already
backup_dir = os.path.join(dir, BACKUP_DIR)
if not os.path.exists(backup_dir):
os.mkdir(backup_dir)
for filename in sorted(filenames):
# on mac os x samba shares, sometimes ._*.wma files are present;
# skip these
if filename.startswith("."):
continue
if filename.endswith(".wma"):
print "Dumping audio for %s ..." % (filename)
wma_filename = os.path.join(dir, filename)
wma_backup = os.path.join(backup_dir, filename)
convert_wma_to_mp3(wma_filename)
os.rename(wma_filename, wma_backup)
if __name__ == "__main__":
path = sys.argv[1]
os.chdir(WORKING_DIR)
convert_wma_files(path)
Syndicated 2009-09-07 22:47:00 (Updated 2009-09-07 23:02:06) from Duncan McGreggor
Twisted Ping.fm Client
#!/usr/bin/python
import sys
from ConfigParser import SafeConfigParser
from twisted.internet import reactor
from pyngfm.client import PingFMAsyncClient
def checkMessage(message):
if len(message) > 140:
print "Message is too long! (%s chars)" % len(message)
sys.exit(1)
def getKeys():
cred_file = "/etc/ping.fm.creds"
config = SafeConfigParser()
config.read([cred_file])
api_key = config.get("default", "api-key")
user_app_key = config.get("default", "user-app-key")
return api_key, user_app_key
def pingIt(message):
def check_result(status):
print status
def check_error(error):
print error.getErrorMessage()
def finish(ignored):
reactor.stop()
pinger = PingFMAsyncClient(*getKeys())
deferred = pinger.user_post("status", body=message)
deferred.addErrback(check_error)
deferred.addCallback(check_result)
deferred.addErrback(check_error)
deferred.addCallback(finish)
if __name__ == "__main__":
message = " ".join(sys.argv[1:])
checkMessage(message)
pingIt(message)
reactor.run()
Syndicated 2009-09-07 22:20:00 (Updated 2009-09-07 22:45:33) from Duncan McGreggor
oubiwann certified others as follows:
Others have certified oubiwann as follows:
[ Certification disabled because you're not logged in. ]
FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!