vrypan — panayotis vryonis
My blog is a digital scrapbook of ideas, thoughts and personal events. My home is vrypan.net.
Home — Archive: All · English · Greek — RSS Feeds: full feed · other options
#misc #misc #en

posting from python to WP

For the last couple of days, I've been experimenting with a new format for my podcast. During the day I record little "audionotes" on my mobile phone. At the end of the day I move these .wav files to my MacBook Pro and use a bunch of scripts to automatically paste them together, generate the MP3 file, upload it to Amazon S3, and post a new entry to my greek blog.

To do this, I've written a couple of quick'n'dirty scripts in python and bash. Most of the code is ugly, and amy things are hardcoded in there. But I think someone may find them useful.

Here is one of them, post2wordpress.py. It is called from the command line like python post2wordpress.py mymp3file.mp3. It uses eyeD3 to extract some basic info from the MP3 file, and python-blogger to post a new entry to my wordpress blog.


# coding=utf-8

import pyblog
import eyeD3
import fnmatch
import os
import datetime
import sys

blog = pyblog.WordPress('http://vrypan.net/weblog/xmlrpc.php', 
        'username', 'password')

tag = eyeD3.Tag()
if len(sys.argv)>2:
        directory = sys.argv[2]
        directory = './mp3'

f = sys.argv[1]
filename = os.path.join(directory,f)
filesize = float(os.stat(filename).st_size) / 1048576.0;

size = str(os.stat(filename).st_size)

title = tag.getTitle()
body = 'duration: '+eyeD3.Mp3AudioFile(filename).getPlayTimeString() + '\n'
body = body + 'download: '+f+''
body = body + " [%.2f MB] \n" % filesize
body = body + 'more info...'

data = {
                'description': body,
                'categories': ['audionotes'],
                'post_status': 'private',
                'custom_fields': [{'value': 'http://audionotes.vrypan.net/'+f+'\n'+size+
                        '\naudio/mpeg', 'key': 'enclosure'}]
Share this post:
The Letter is a newsletter I send out whenever I have something to say or share. It may take a few days, weeks or months for the next one.
Privacy: I hate spam as much as you do, maybe more. I will not share your email with advertisers, etc.