Move main logic into a main() function

Change-Id: I2ec349b2bb0362e07e68ca65bb9464b67f80a5df
Put two blank lines between functions and classes

Change-Id: I02a6dbf012f9f65908ac0cbd3e9bc945db818aa7
General style and cleanliness tweaks

- Let the logging functions interpolate string arguments
- Use dict comprehension syntax (python >= 2.7)
- Get the current system time once per execution instead of repeatedly
  during the main loop.
- Use the module docstring to hold usage text.

pylint and pep8 are less grumpy now :-)

Change-Id: I09cb7686688945c1954e3f42ac7db10e2264440f