Use `with` instead of manually closing the file

`with` assures that the __exit__(...) method will be called on objects
once the block is exited. In the case of files, that will call the
close() method so that you don't have to remember to do it yourself.
Use implicit falseyness of 0
Refactor open_cb
Remove unnecessary variable
Refactor command-line runner code

`if __name__ == '__main__'` will assure that this code will not be run
if imported. Using the `registered` dictionary is maybe just personal
preference, but I think it's a little more elegant than a large if/else.
It's also slightly easier to extend, though not by much.