Last active
December 31, 2015 11:59
-
-
Save cympfh/7983655 to your computer and use it in GitHub Desktop.
コミットコメントを考えてくれます
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(/</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