$ node index https://call.stage.mozaws.net/config.js | python test.py$ node index https://hello.firefox.com/config.js | python test.py| #!/usr/bin/env node | |
| "use strict"; | |
| var minimist = require("minimist"); | |
| var request = require("request"); | |
| var argv = minimist(process.argv.slice(2)); | |
| var HELLO_CONFIG_URL = argv._[0]; | |
| if (!HELLO_CONFIG_URL) { | |
| console.error("Must specify a URL to parse. Usage: %s <url>", process.argv[1]); | |
| process.exit(1); | |
| } | |
| request.get(HELLO_CONFIG_URL, function (err, res, data) { | |
| if (err) { | |
| console.error(err); | |
| process.exit(2); | |
| } | |
| var code; | |
| try { | |
| code = eval(data); | |
| console.log(JSON.stringify(code, null, 2)); | |
| } catch (err) { | |
| console.error(err); | |
| process.exit(3); | |
| } | |
| }); |
| { | |
| "name": "get-hello-config", | |
| "version": "1.0.0", | |
| "author": "Peter deHaan <peter@deseloper.com> (http://nodeexamples.com/)", | |
| "dependencies": { | |
| "minimist": "1.2.0", | |
| "request": "2.69.0" | |
| }, | |
| "keywords": [], | |
| "license": "WTFPL", | |
| "main": "index.js", | |
| "bin": { | |
| "get-hello-config": "index.js" | |
| }, | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| } | |
| } |
| import json | |
| import sys | |
| data = json.load(sys.stdin) | |
| print(data["serverUrl"]) | |
| print(json.dumps(data, sort_keys=True, indent=2)) |