Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
コミットコメントを考えてくれます
var exec = require('child_process').exec
, fs = require('fs')
var url = 'http://データベース/';
// 今日の夕食費
var kasi = 300
, time = 20
, www = kasi-time; // com
// 時は金なり
randomItem(function(item) {
randomLine(item, console.log)
});
function randomItem(cont) {
exec('wget -O /tmp/kasihtml ' + url + 'ranking.php?cat=month'
, function(err, stdout, stderr) {
var doc = fs.readFileSync('/tmp/kasihtml', 'utf8');
var items = collect(doc, /item-[0-9]*.html/);
cont(items[Math.random() * items.length | 0]);
});
}
function collect(txt, pat) {
if (!pat.test(txt)) {
return [];
} else {
var result = txt.match(pat);
return collect(txt.slice(result.index + result[0].length), pat)
.concat(result[0])
}
}
function randomLine(item, cont) {
var id = item.match(/item-(\d*).html/)[1];
exec('wget -O /tmp/kasihtml ' + url + '/item_js.php?no=' + id
, function(err, stdout, stderr) {
var doc = fs.readFileSync('/tmp/kasihtml', 'utf8');
var idx = doc.indexOf("'")
, idy = doc.lastIndexOf("'");
var ls =
doc.slice(idx+1, idy)
.replace(/ /g, ' ')
.replace(/>/g, '>')
.replace(/&lt;/g, '<')
.split('<br>')
.filter(function(l) { return l.length > 5 });
cont(ls[Math.random()*ls.length | 0]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment