transformUserAgentStrings: function (fromFile, fileTo) { var self = this; var userAgentStrings = []; lineReader.eachLine(fromFile, function (line, last) { var splited = line.split('\t'); if (splited.length == 2) { userAgentStrings.push({amount: parseInt(splited[0].trim()), userAgentString: splited[1].trim(), browser: undefined}); } if (last) { async.mapLimit(userAgentStrings, 1, self.fillInBrowser, function (err, stat) { var merged = self.mergeUserAgentString(stat); merged = _.sortBy(merged, function (a) { return -a.amount; }); var stream = fs.createWriteStream(fileTo); stream.once('open', function (fd) { for (var i = 0; i < merged.length; i++) { stream.write(merged[i].browser + '\t' + merged[i].amount + '\n') } stream.end(); }) }) } }); },
var startProcess = function(){ lineReader.eachLine(gfwListFileName, function(line) { processGfwlistLine(line); }).then(function () { reverseIP(); }); }
function readFile(filename) { filename = filename || DEFAULT_FILE; var where = path.join(__dirname, filename); console.log('Reading file:', where); lineReader.eachLine(where, function(line) { if (program.verbose) console.log('Processing', line); var matches = line.match(REGEX); if (!matches || matches.length < 4) { console.log('Could not process', line); process.exit(1); } var parts = matches[1].split(' '); if (parts.length == 2) { insertPlayer({ firstname: parts[0], lastname: parts[1], team: matches[2], position: matches[3] }); } else { console.warn('Skipping ambigious name', matches[1]); } }); }
function loadBody() { lineReader.eachLine('KCBE.xml', function (line, last) { i = i + 1; if(i >= 16) { lt1 = line.indexOf("<"); gt1 = line.indexOf(">"); lt2 = line.lastIndexOf("<"); lt1 = lt1 + 1; key = line.substring(lt1, gt1); gt1 = gt1 + 1; value = line.substring(gt1, lt2); weatherData[key] = value; } if(last) { delete weatherData[key]; //for(key in weatherData) { //show = "Key: " + key + " Value: " + weatherData[key]; //} body = '<html>'+ '<head>'+ '<meta http-equiv="Content-Type" '+ 'content="text/html; charset=UTF-8" />'+ '</head>'+ '<body link=\"#000000\" vlink=\"#000000\">'+ '<b>' + weatherData["location"] + '</b><br />' + '<i>' + weatherData["observation_time"] + '</i><br /><br />' + '<table align=\"left\" valign=\"top\" width=\"95%\" border=\"0\"><tr><td width=\"30%\"><img src=\"' + weatherData["icon_url_base"] + weatherData["icon_url_name"] + '\" alt=\"Weather Icon\" width=\"56\" height=\"56\"></td><td width=\"70%\" align=\"center\"><h3>' + weatherData["temperature_string"] + '</h3><a href=\"http://radar.weather.gov/ridge/Conus/northeast_loop.php\" target=\"_blank\">Radar Loop</a></td></tr></table>' + weatherData["weather"] + '<br /><br />Winds: ' + weatherData["wind_string"] + '</body>'+ '</html>'; } }); }
return new Promise(function (resolve,reject) { console.log("read file to tree....:"+file) lineReader.eachLine(file,function (line,last,cb) { if(first){ if(!check(line)){ cb(false) reject() }else{ cb(true) } first = false; return; } cb(true) line = line.split("-") switch (line.length){ case 1: tree[line[0]] = tree[line[0]] || [] break; default: tree[line[0]] = tree[line[0]] || [] tree[line[0]].push(line.join("-")) break; } if(last){ console.log("read file success:"+file) resolve(tree) } }) })
function insertData() { var somevalue = 2; for (var i = 0; i < somevalue; i++) { console.log(i); var x = null; // read line by line: lineReader.eachLine('stocks.json', function (line, last) { // console.log("what is last", last); var stocks; var stocksid; // console.log("RAW DATA:", line); stocks = JSON.parse(line); stocksid = JSON.stringify(i) + JSON.stringify(stocks._id); //console.log("THE ID:", stocksid); delete stocks._id; //console.log("DEBUG:", stocksid, stocks); myBucket.upsert(JSON.stringify(stocksid), JSON.stringify(stocks), function (err, result) { if (err) { x++; console.log("ERR:", stocksid, x, err.message); } else { //console.log("DONE!"); } }); if (last) { return false; // stop reading cb.shutdown; } }); } }
importer.parseLogAndImport = function () { lr.eachLine(cfg.log, function (line, last) { console.log('processing: "', line, '"'); importer.addMessage(line, function (err, result) { if (err) { console.log('ERROR: ', err); return false; } else { cfg.rowCount++; console.log('OK: ', line); console.log('Added row #' + cfg.rowCount); } }); /* if (cfg.rowCount >= 5) { return false; process.exit(); } */ }).then(function () { console.log('Imported ' + cfg.rowCount + ' lines in ' + moment().fromNow(cfg.importStart)); process.exit(); }); };
module.exports.readcode = function(file,move,home, set){ lineReader.eachLine(file, function(line) { if(line.match(/^G1/)){ move(line); } if(line.match(/^G28/)){ home(); } if(line.match(/^G20/)){ set(0,1); } if(line.match(/^G21/)){ set(0,0); } if(line.match(/^G90/)){ console.log("This machine does not support absolute positioning."); console.log("Stoping Build."); set(1,0); return false; } }).then(function(){ console.log('finished file: '+file); }); };
/* * filterNumber.txt调用百度接口 * */ function readNumberRegionEx() { linereader.eachLine('filterNumber.txt', function (line) { let arr = line.toString().split(' '); let number = arr[1] + '6560'; console.log(number); httpsGet(addressUrl + number, function (res) { let datas = []; let size = 0; res.on('data', function (data) { datas.push(data); size += data.length; }); res.on("end", function () { let buff = Buffer.concat(datas, size); let result = iconv.decode(buff, "gb2312");//转码//var result = buff.toString();//不需要转编码,直接tostring let index = result.indexOf('('); let dataStr = result.substr(index + 1, result.length - index - 3); let dataJson = JSON.parse(dataStr); if (dataJson.status === '0') { if (dataJson.data.length === 0) { appendFile(arr[1].substr(0, 3), arr[1] + '\r\n', numberSegmentByLocalNone); } else { let data = dataJson.data[0]; data.prov = !!data.prov ? data.prov : data.city; let txtContent = `${data.key.substr(0, 3)} ${data.key} ${data.prov} ${data.city} ${data.type}\r\n`; appendFile(data.key, txtContent, numberSegmentByLocal); } } }); }); }); }
exports.generate = function() { var fs = require('fs'); var lineReader = require('line-reader'); var S = require('string'); fs.exists("db/movies.dat", function (exists) { if (!exists) { console.log('Movies.dat database not found.'); process.exit(1); } }); var db = { name: 'movies-database', version: 1, aaData: [] }; /*** Rules <- A | B Sample <- 1::Toy Story (1995)::Animation|Children's|Comedy A <- /::/ match "::" B <- /\((\d+)\)/ match "(1995)" Result <- '1' 'undefined' 'Toy Story ' '1995' '' 'undefined' 'Animation|Children's|Comedy' ***/ lineReader.eachLine('db/movies.dat', function(line, last) { //console.log(line); var arr = line.split(/::|\((\d+)\)/); db.aaData.push([arr[0], S(arr[2]).trim().s, arr[3], S(arr[6]).trim().truncate(25).s]); }).then(function () { fs.writeFile("public/movies.json", JSON.stringify(db)); console.log('Movie JSON was created successfully!'); }); };
var exe = exec("./tc " + " " + testcase_file_path + " " + testcase_name , function (err, out, derr) { if (err !== null) console.log('executable err: ' + err); // send line colors var line_colors = {}; var splitted_line; lineReader.eachLine('line_colors.txt', function(line, last_line) { splitted_line = line.split(" "); line_colors[splitted_line[0]] = splitted_line[1]; if (last_line) { splitted_line = line.split(" "); line_colors[splitted_line[0]] = splitted_line[1]; //console.log(JSON.stringify(line_colors)); socket.emit('Line_Colors', JSON.stringify(line_colors)); var cov_tc_result = {}; var testcase_num; var counter = 0; var tc_result; lineReader.eachLine('testcase_result_cov.txt', function( first_line, end_line) { console.log(first_line); if (counter == 0) testcase_num = first_line; else tc_result = first_line; ++counter; if (end_line) { cov_tc_result[testcase_num] = tc_result; console.log(JSON.stringify(cov_tc_result)); socket.emit('tc_cov_result', JSON.stringify(cov_tc_result)); } }); } }); });
exports.convertTxtToFeatureJson = function (filePath, outFile) { var data = []; lineReader.eachLine(filePath, function (line, last, cb) { var parsedData = line.split(','); var output = parsedData.splice(parsedData.length - 1); for(var i = 0; i < parsedData.length; i++){ parsedData[i] = Number(parsedData[i]); } data.push({ input: parsedData, output: Number(output[0]), raw: line }); if (last) { var shuffledData = _.shuffle(data); fs.writeFile(outFile, JSON.stringify(shuffledData), function (err) { if (err) { console.log(err) } }); } else { cb(); } }); };
exports.convertToJson = function (filePath, outFile) { var data = []; lineReader.eachLine(filePath, function (line, last, cb) { if (line.indexOf('ham') === 0) { data.push({ text: line.slice(3).trim(), spam: false }); } else { data.push({ text: line.slice(4).trim(), spam: true }); } if (last) { var shuffledData = _.shuffle(data); fs.writeFile(outFile, JSON.stringify(shuffledData), function (err) { if (err) { console.log(err) } }); } else { cb(); } }); };
function isTodaySpecial() { // check if today is in the list of special days var t_its=0; var d = new Date(); var td = d.getDate(); var tm = d.getMonth()+1; lineReader.eachLine('config.txt', function(line, last) { if ((line[0]==';') || (line.length == 1)) { // ignore this line } else { if (line.indexOf('DATE') == 0) { var i = line.indexOf('=')+1; var l = line.substring(i,line.length).trim(); var res = l.split(","); if ((res[0] == td) && (res[1] == tm)) { t_its = res[2]; } } } if(last){ its = t_its; return false; } }); }
function readFirstLine(file, callback){ lineReader.eachLine(CONTENT_DIR + '/' + file, function(line, last) { callback(line); return false; // stop reading the file }); }
var grouper = function (obj) { console.log("In grouper"); lineReader.eachLine(obj.mapper_output, function(line, last) { var words = line.split(","); var fileName = obj.grouper_output_dir + "grouper-" + words[0].replace(/(\r\n|\n|\r)/gm,"") + ".txt"; fs.appendFile(fileName, words[1].replace(/(\r\n|\n|\r)/gm,"") + ","); }) }
function loadData(filePath, leafIndex, suggestTable, callback) { lineReader.eachLine(filePath, function(line) { var entry = JSON.parse(line); if (entry.leaf === leafIndex) { suggestTable[entry.key] = entry.suggestions; } }).then(callback); }
joblist : function (callback) { // read all lines: lineReader.eachLine(basename_joblist, function (line) { var job = line.trim(); if (job.length > 0) jobList.push(job); }).then(function () { callback(null, jobList.length); }); },
exports.loadArray = function (fileName, cb) { var arr = []; lineReader.eachLine(fileName, function(line) { if(line.length) { arr.push(~~line); } }).then(function () { cb(arr); }); }
function (callback) { // read all lines: lineReader.eachLine(basename_keyword, function (line) { keywords.push(line.trim()); count++; }).then(function () { last = true; callback(); }); },
similarity : function (callback) { // read all lines: lineReader.eachLine(basename_sim, function (line) { var vector = line.trim(); if (vector.length > 0) { vectors.push(JSON.parse('[' + vector + ']')); // convert from strings to Double array } }).then(function () { callback(null, vectors.length); }); }
function READ(){ lineReader.eachLine('file.txt', function(line, last) { console.log(line); // do whatever you want with line... sendData(line); if(last){ // or check if it's the last one sendData(line); } }); }
constructor(filepath, onLine, onClose) { let index = 0; readline.eachLine(filepath, (line, last) => { if (onLine) { onLine(line, index++, last); } if (last || this.error) { onClose(this.error); return false; } }); }
TodoApp.prototype.loadTodoFile = function() { var self = this; var lineReader = require("line-reader"); self.taskList = new TaskList(); lineReader.eachLine(self.prefs.todoTxtFile, function(line) { if (line && line.length > 0) self.taskList.addTask(new Task(line)); }).then(function () { self.loadProjectsAndContexts(); self.reloadTasks(); }); };
//读取sender.txt文件,获取所有发送人用户名和密码 function(cb){ line_reader.eachLine("sender.txt", function(line, last){ if(line.trim().length > 0 && !S(line).startsWith('#')){ senders.push(line); } if(last){ // console.log("------- sender list ------"); // console.log(senders); cb(null, "senders list length = "+ senders.length); } }); },
return new Promise(function(resolve, reject) { lineReader.eachLine(self.fname, function(line, last) { try { self.onLine(line) } catch (e) { return reject(e); } if (last) { return resolve(self.directives); } }) })
router.post('/load', upload.single('rosters'), function(req, res, next) { // check if an instructor uploaded rosters file console.log(req.file); var rosters_file = temp_folder + req.file.filename; var counter = 0; // count the number of lines var num_new_tas = 0; // count the number of newly added tas var fields, first_name_index, last_name_index, utorid_index, student_number_index, email_index, weight_index; var ta_model = require('./models/ta_model.js'); console.log(rosters_file); lineReader.eachLine(rosters_file, function(line, last) { if (counter == 0) { // find index of each filed fields = line.split(','); first_name_index = fields.indexOf("First Name"); last_name_index = fields.indexOf("Last Name"); utorid_index = fields.indexOf("UTORiD"); student_number_index = fields.indexOf("Student Number"); email_index = fields.indexOf("Email"); weight_index = fields.indexOf("Weight"); } else { var values = line.split(','); // create a new ta var new_ta = new ta_model({ first_name : values[first_name_index], last_name : values[last_name_index], utorid : values[utorid_index], student_number : values[student_number_index], email : values[email_index], to_review : [], to_grade : [], weight : values[weight_index], is_active : true }); // write a new ta into database new_ta.save(function (err) { if (err) { console.log(err); } else { num_new_tas++; } }); } counter++; // reach EOF if (last) { console.log(num_new_tas + ' new tas are added'); fs.unlinkSync(rosters_file); res.redirect('/create_tas'); } }); });
var get_md_preview = function(file, complete_cb) { var preview = ''; linereader.eachLine(file, function(ln, last, cb) { preview += ln + "\n"; if (/* /^(?:[\*_\-] ?)+$/.test(ln) || */ last) { cb(false); complete_cb(null, preview); } cb(true); }); }
joburl : function (callback) { // read all lines: lineReader.eachLine(basename_joburl, function (line) { var urlPair = line.trim(); var record; if (urlPair.length > 0) { record = urlPair.split(','); jobUrl[record[0].trim()] = record[1].trim(); } }).then(function () { callback(null, Object.keys(jobUrl).length); }); },
function main(wordlist,host) { smtp.host = host; var lineReader = require('line-reader'); lineReader.eachLine(wordlist, function(line, last) { if (last) { smtp.start(2); } else { smtp.queue.push(line); } }); }