Skip to content

Instantly share code, notes, and snippets.

@cympfh
Last active December 31, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cympfh/7983655 to your computer and use it in GitHub Desktop.
Save cympfh/7983655 to your computer and use it in GitHub Desktop.
コミットコメントを考えてくれます
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