'use strict';

const scraper = require('./src/scraper');
const database = require('./src/data-adapters/sperm-whale');

const stream = scraper.startScrapeStream();

stream.on('data', (course) => {
  database.insertCourse(course, function(err, r) {
    if (err) {
      database.close();
      process.err(err);
    } else {
      console.log(`inserted ${course.subjectCode} ${course.courseNumber}`);
    }
  });
});

stream.on('end', () => {
  console.log('done.');
  database.close();
  process.exit();
});
@@ -56,16 +56,474 @@
 ;%0Aconst 
+stream = scraper.startScrapeStream();%0Aconst Transform = require('stream').Transform;%0A%0Aconst stringify = new Transform(%7B%0A  writableObjectMode: true,%0A%0A  transform(chunk, encoding, callback) %7B%0A    callback(null, JSON.stringify(chunk));%0A  %7D%0A%7D);%0A%0Aif (process.argv.includes('--console')) %7B%0A  // Pipe output to stdout for debugging purposes%0A  stream.pipe(stringify, %7B objectMode: true %7D)%0A        .pipe(process.stdout);%0A%7D else %7B%0A  // Pipe output to database%0A  const 
 database
@@ -570,57 +570,13 @@
 ale'
-);%0A%0Aconst stream = scraper.startScrapeStream(
 );%0A
-%0A
+  
 stre
@@ -603,16 +603,18 @@
 e) =%3E %7B%0A
+  
   databa
@@ -653,15 +653,14 @@
 (err
-, r
 ) %7B%0A
+  
     
@@ -672,24 +672,26 @@
 rr) %7B%0A      
+ 
+ 
 database.clo
@@ -696,16 +696,18 @@
 lose();%0A
+  
       pr
@@ -726,16 +726,18 @@
 r);%0A    
+ 
+ 
 %7D else %7B
@@ -737,16 +737,18 @@
  else %7B%0A
+  
       co
@@ -823,21 +823,29 @@
     
+  
 %7D%0A  
+ 
+ 
 %7D);%0A
+  
 %7D);%0A%0A
+  
 stre
@@ -867,16 +867,18 @@
  =%3E %7B%0A  
+ 
+ 
 console.
@@ -891,16 +891,18 @@
 one.');%0A
+  
   databa
@@ -915,16 +915,18 @@
 se();%0A  
+ 
+ 
 process.
@@ -933,11 +933,17 @@
 exit();%0A
+  
 %7D);
+%0A%7D%0A%0A

Create stdout connector & command line option