#!/usr/bin/env python

# by carlcarl

import getopt, sys
import hmac
import hashlib
import base64
import urllib

def formattedCmd(api, cmd):
    s = 'apiKey=' + api + '&' + cmd
    return s

def encypt(string, key):
    h = hmac.new(key, string, hashlib.sha1)
    return base64.b64encode(h.digest())

def formattedUrl(baseUrl, api, cmd, signature):
    url = baseUrl + '?' + formattedCmd(api, cmd) + '&' + urllib.urlencode({'signature': signature})# signature=' + urllib.quote(signature)
    return url

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'u:a:s:', ['help', 'output='])
    except getopt.GetoptError, err:
        print str(err)
        usage()
        sys.exit(2)

    baseUrl = 'http://*.*.*.*:8080/client/api'
    cmd = api = secret = None

    for o, a in opts:
        if o == '-u':
            cmd = a
        elif o == '-a':
            api = a
        elif o == '-s':
            secret = a
        else:
            assert False, 'unhandled option'

    newCmd = formattedCmd(api, cmd).lower()
    signature = encypt(newCmd, secret)
    url = formattedUrl(baseUrl, api, cmd, signature)

    print '\n' + url

if __name__ == '__main__':
    main()


@@ -44,17 +44,23 @@
 t getopt
-,
+%0Aimport
  sys%0Aimp
@@ -112,16 +112,17 @@
 urllib%0A%0A
+%0A
 def form
@@ -191,16 +191,17 @@
 turn s%0A%0A
+%0A
 def ency
@@ -302,16 +302,17 @@
 est())%0A%0A
+%0A
 def form
@@ -454,47 +454,8 @@
 re%7D)
-# signature=' + urllib.quote(signature)
 %0A   
@@ -467,16 +467,17 @@
 rn url%0A%0A
+%0A
 def main
@@ -632,24 +632,8 @@
 rr)%0A
-        usage()%0A
     
@@ -1128,16 +1128,16 @@
 ain__':%0A
+
     main
@@ -1139,9 +1139,8 @@
  main()%0A
-%0A

Fix style with pylint