Skip to content

Instantly share code, notes, and snippets.

@lazypower
Created January 22, 2012 07:39
Show Gist options
  • Save lazypower/1656111 to your computer and use it in GitHub Desktop.
Save lazypower/1656111 to your computer and use it in GitHub Desktop.
#!/usr/bin/python2.4
import httplib, urllib, sys
# Define the parameters for the POST request and encode them in
# a URL-safe format.
params = urllib.urlencode([
('js_code', open(sys.argv[1], 'r').read()),
('compilation_level', 'WHITESPACE_ONLY'),
('output_format', 'text'),
('output_info', 'compiled_code'),
])
# Always use the following value for the Content-type header.
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = httplib.HTTPConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
data = response.read()
print data
conn.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment