Convert main() function to python idiom

It allows the module to be used either as a library module, or as a standalone script
Merge pull request #1 from oaubert/patch-1

Convert main() function to python idiom