A Python-MySQL Project

I assigned myself a project for the weekend, writing a little program that I could use to disable comments on blog posts based on their age. Python’s already installed on the Mac, so I figured it’d be pretty easy to use that to make updates to my WordPress database.

The first thing needed is the connecter to allow Python to talk to a MySQL datbase, mysql-python. The setup program for the newest version, 1.2.2, didn’t want to run for me and the hints I found around the ‘net didn’t seem to apply, so I downloaded version 1.2.1_p2. There was still some work to do to get it to install though.

To install the connector, MySQL needed to be installed locally first. Sun now owns MySQL but fortunately there’s a Community version available for download free of charge for personal use.

Once that’s installed, it’s back to the MySQL-Python connector installation. Several sites had notes which helped me find that setup.py tries to call mysql_config but can’t find it, so I edited the line from ...popen("mysql_config... to ...popen("/usr/local/mysql/bin/mysql_config...

The setup program gave me another error, this time because I don’t have gcc installed – to complete the build it needs to be able to call the C compiler. Back when I set up my PowerBook I’d not installed that part of the developer tools, so I had to dig out my OS X disks and do that. Then finally the setup worked cleanly:

python setup.py clean
python setup.py build
python setup.py install

Now that all the bits are in the right places, I’m finally ready to start getting some code going. I added permission to my databases, creating a new user that has remote access, and used that.

# use the connector library
import MySQLdb
# connect to the database, using the correct username and password
conn = MySQLdb.connect (host = "vorefamily.net", user = "my_db_username", passwd = "my_db_password", db = "my_database") # look in your wp-config.php file to find the right database
# update the fields, using an SQL call
conn.query("""UPDATE wp_posts SET comment_status = 'closed' WHERE year(post_date) < 2008 """) # close the database connection conn.close ()

It's not long or fancy, but it does exactly what was needed at the moment. I'll build more of a wrapper around it later, to make it more flexible, add error checking etc.

An evening of forensic work while watching a movie with my family, followed by some light development this morning... success. And, perhaps more importantly, it gets my system back to a place where I can start digging into larger projects I've been thinking about.

Got Firebug?

Web developers, have you looked into and downloaded Firebug yet? I just came across a mention of it on Matt’s weblog and it certainly looks worth a good look or three. Integrating live website editing — CSS, HTML, Javascript — fight into Firefox! Watch Jesse Newland’s screencast and I think you’ll be as interested as I am.

There are still many whole-site managment features that Dreamweaver has that Firebug doesn’t appear to, but I’m wondering… could this be the open-source project that puts a dent in for DW and other “full-featured” web development tools?

[later] see comments from Firebug creator Joe Hewitt.

They Won’t Take Your Money?

Mike McBride asks for some experiential information from Mac users:

My wife was doing a little on-line shopping today on her Mac and ran into a couple of sites that wouldn’t accept her credit card information. The transactions failed in both Firefox and Safari.

I’ve never had a problem with a shopping site taking my credit card, using Firefox or Safari. The problems that I do run across every now and then are sites that do browser & O/S checking badly (parts of Kaiser Permanente’s site refuse to display on anything other than IE5+/Win, even though their techs swear that they’re completely standards-compliant and browser-neutral) or that insist on using ActiveX components (these are getting fewer and fewer, fortunately.

Shopping sites though? Nope, nobody seems to have any problem taking my money.

Mike, I’d be curious to know what sort of errors she was getting, and what sites they were if you don’t mind sharing.

Me – Off The Net?

I mentioned I’d been off the net today; the funny thing is that I was productively working on a website. E, at TPI, has been good to me in these few months, contracting me to build their new site and finding other gigs to work on for her. This week they’ve got a contract for some content and part of that is web-based, so they called me. I really appreciate that, thanks.

Oh, and as for off the net today – they’re moving their office down the hall, so things are in a bit of disarray. No biggie, we had everything we needed. It was actually pretty nice, working without any network distractions.

A New Site Goes Live

TPI's old websiteFor a few weeks now, I’ve been working on a website project for Tomorrow Pictures, Inc. Their old site, while functional, hadn’t been updated in several years and they weren’t happy with it. They had some ideas, including the color scheme and some basic elements, and we worked together to come up with a design that both pleases them and that they believe will appeal to their customers – both current and potential.

The new site incorporates their new logo and themes, and showcases some of the video work they’ve done recently.TPI's new website Behind the scenes, I’ve made it much easier for them to maintain. Very little is hard-coded; most of the text & links is read from easily-edited text files, and all the thumbnails & videos are “found” by the site’s scripts. When Drew wants to update the shows, he can just delete the thumbnail and movie files and a pair of text files with the descriptions and upload new ones. The site’s scripts dynamically serves up the thumbnails and creates links for the movies, while putting the descriptive text into rollovers and in the movie viewer window.

Of course, as with any project, there’s the possibility of errors or omissions, in either the code or content – and if you see any please let me know. [edit: a week later and nothing’s been noticed as ‘wrong’ yet – that’s always good news] For starters though, Drew and the folks at TPI are very happy with the look and are even happier that they’ll be able to keep it updated without the hassle.