Export Silverstripe Comments to WXR

I recently had to migrate a Silverstripe installation’s comments to use the Disqus comment system. Here’s the script I wrote to grab and format the Silverstripe comments into the WXR xml structure Disqus can import. No doubt there’s an easier way....