Check if file exists.
Guess mime type by file extension.

While this works for many files, it will fail for files without
extension. Perhaps using python-magic as optional library would do a
better job.
Execute code only if it's the main script.