File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ var async = require('async');
44
55var openProductsPage = require ( './lib/openProductsPage' ) ;
66var openCardPage = require ( './lib/openCardPage' ) ;
7+ var writeCardsToFile = require ( './lib/writeCardsToFile' ) ;
78
89/** @type Card[] */
910var userCards = [ ] ;
@@ -63,6 +64,8 @@ function allProductsGotten() {
6364 console . log ( userCards [ i ] . trend ) ;
6465 console . log ( '---' ) ;
6566 }
67+
68+ writeCardsToFile ( userCards ) ;
6669
6770 phantom . exit ( ) ;
6871 } ) ;
Original file line number Diff line number Diff line change 1+ /* global phantom */
2+
3+ var fs = require ( 'fs' ) ;
4+
5+ /**
6+ * JSON encode the provided array and write it on the "/data" folder of the project
7+ *
8+ * @param {Card[] } userCards
9+ */
10+ function writeCardsToFile ( userCards ) {
11+ var file = fs . workingDirectory + '/data/' + Date . now ( ) + '.json' ;
12+
13+ try {
14+ fs . write ( file , JSON . stringify ( userCards ) , 'w' ) ;
15+ } catch ( e ) {
16+ console . error ( 'Error writing data:' , e ) ;
17+
18+ phantom . exit ( ) ;
19+ }
20+ }
21+
22+ module . exports = writeCardsToFile ;
You can’t perform that action at this time.
0 commit comments