You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.0 KiB

const loli = require("./loli");
var cfg = new loli.Config();
var verbose = false;
var debug = false;
process.argv.forEach(function (val, index, array) {
if(index>1) {
if (val == "--verbose")
verbose = true;
else if(val == "--debug")
debug = true;
else if (/^--number=/.test(val))
cfg.number = val.replace(/^--number=/, "");
else if (/^--range=/.test(val))
cfg.range = val.replace(/^--range=/, "");
else if (/^--page=/.test(val))
cfg.page = val.replace(/^--page=/, "");
else {
if(!cfg.tags)
cfg.tags = [];
cfg.tags.push(val);
}
}
});
function puts(str) {
console.log("DBG "+str);
}
if (debug)
cfg.debug = puts;
if (cfg.number > cfg.range)
cfg.range = cfg.number;
loli.randomise(function(datas) {
if (this.error) {
if(verbose)
console.log(JSON.stringify([{error: this.error}]));
else if(debug) console.log("Error: "+this.error);
}
else if(verbose)
console.log(JSON.stringify(datas));
else {
datas.forEach(function(data, i, a) {
if(data)
var url = data.file_url;
console.log(url);
});
}
}, cfg);