Skip to content

Instantly share code, notes, and snippets.

@walkure
Created March 13, 2017 18:24
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 walkure/6158ac8cd58eb3b28a813904bdcaed80 to your computer and use it in GitHub Desktop.
Save walkure/6158ac8cd58eb3b28a813904bdcaed80 to your computer and use it in GitHub Desktop.
ないんたん駒場( http://sx9.jp/weather/tokyo.html )の情報を読み込んでCSVに変換
#!/usr/local/bin/node
const http = require('http');
const vm = require('vm');
const fs = require('fs');
const util=require('util');
const url = 'http://sx9.jp/weather/tokyo-komaba.js';
const dst = '/dev/shm/ninetan/';
http.get(url, function(res) {
var body = '';
res.setEncoding('utf8');
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(res){
var sandbox = {
list: [],
data: {
setValue: function(rowNum,rate,prob){
if(sandbox.list[rowNum] === undefined){
sandbox.list[rowNum] = [];
}
// console.log("rowNum:"+rowNum+" rate:"+rate+" prob:"+prob);
sandbox.list[rowNum][rate] = prob;
},
addRows: function(rows){}
}
};
body += 'update_tokyo_komaba(data);'
vm.runInNewContext(body,sandbox);
if(!fs.existsSync(dst)){
fs.mkdirSync(dst);
}
fs.writeFile(dst+'/komaba_0min',sandbox.list[0].join(','),function(e){if(e)console.log(e.message);});
fs.writeFile(dst+'/komaba_15min',sandbox.list[15].join(','),function(e){if(e)console.log(e.message);});
fs.writeFile(dst+'/komaba_60min',sandbox.list[60].join(','),function(e){if(e)console.log(e.message);});
fs.writeFile(dst+'/komaba_120min',sandbox.list[120].join(','),function(e){if(e)console.log(e.message);});
console.log('ok');
});
}).on('error', function(e){
console.log(e.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment