22
33// here we will convert the search.sh script into JS
44import { format , sub } from 'date-fns' ;
5- import fs from 'fs' ;
5+ import fs from 'fs/promises ' ;
66import { download , search , sendOutput } from './cli.js' ;
77
88const CATEGORY_ID = 'alzheimers-disease' ;
@@ -23,10 +23,7 @@ const OUTPUT_FILE = `${DATA_DIRECTORY}/${CATEGORY_ID}.json`;
2323
2424// Getting all latest articles from BiorXiv
2525console . log ( `Fetching from ${ BIORXIV_SOURCE } between ${ START_DATE } and ${ END_DATE } ` ) ;
26- fs . open ( BIORXIV_FILE , 'w' , function ( err , file ) { // consider changing the callback function if needed
27- if ( err ) throw err ;
28- console . log ( 'Saved!' ) ;
29- } ) ;
26+ fs . open ( BIORXIV_FILE , 'w' ) ;
3027const bioOptions = {
3128 source : BIORXIV_SOURCE ,
3229 output : BIORXIV_FILE
@@ -35,10 +32,7 @@ const bioData = await download(START_DATE, END_DATE, bioOptions);
3532
3633// Getting all latest articles from MedrXiv
3734console . log ( `Fetching from ${ MEDRXIV_SOURCE } between ${ START_DATE } and ${ END_DATE } ` ) ;
38- fs . open ( MEDRXIV_FILE , 'w' , function ( err , file ) {
39- if ( err ) throw err ;
40- console . log ( 'Saved!' ) ;
41- } ) ;
35+ fs . open ( MEDRXIV_FILE , 'w' ) ;
4236const medOptions = {
4337 source : MEDRXIV_SOURCE ,
4438 output : MEDRXIV_FILE
@@ -47,10 +41,7 @@ const medData = await download(START_DATE, END_DATE, medOptions);
4741
4842// Creating a JSON with all the results, both sources combined
4943console . log ( 'Combining results...' ) ;
50- fs . open ( COMBINED_FILE , 'w' , function ( err , file ) {
51- if ( err ) throw err ;
52- console . log ( 'Saved!' ) ;
53- } ) ;
44+ fs . open ( COMBINED_FILE , 'w' ) ;
5445const combinedData = bioData . concat ( medData ) ;
5546const combinedOptions = {
5647 output : COMBINED_FILE
@@ -59,10 +50,7 @@ await sendOutput(combinedData, combinedOptions);
5950
6051// Search for the QUERY keyword in all the downloaded articles & compile the related articles
6152const QUERY = 'alzheimer' ;
62- fs . open ( OUTPUT_FILE , 'w' , function ( err , file ) {
63- if ( err ) throw err ;
64- console . log ( 'Saved!' ) ;
65- } ) ;
53+ fs . open ( OUTPUT_FILE , 'w' ) ;
6654const outputOptions = {
6755 input : COMBINED_FILE ,
6856 output : OUTPUT_FILE
0 commit comments