Create setup.py and move script to a module.
Use codecs.open() instead of open() for backwards compatibility.

older versions of python did not support the encoding argument in the
open() function but the codecs module version of open() did so thats
what we're using. Also updated other open() calls to specify the
encoding argument.