Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Last active March 28, 2016 20:42
Show Gist options
  • Select an option

  • Save pdehaan/20c23a0ba81c691a8474 to your computer and use it in GitHub Desktop.

Select an option

Save pdehaan/20c23a0ba81c691a8474 to your computer and use it in GitHub Desktop.
Load Firefox Hello configs from remote URL.

Usage:

Stage:

$ node index https://call.stage.mozaws.net/config.js | python test.py

Production:

$ 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment