Almost finished.
replaced httplib to urllib2.
some code cleanups.
still needs to complete the format() function.