-
Notifications
You must be signed in to change notification settings - Fork 1
/
frontiersin.js
84 lines (67 loc) · 2.58 KB
/
frontiersin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const { map } = require( "p-iteration" );
const PostResults = require( "../UTILS/mastadonManager.js" ).formatPapersAndPost;
const PrintNowTime = require( "../UTILS/genericUtils.js" ).printNowTime;
const EncodeB64 = require( "../UTILS/genericUtils.js" ).encodeBase64;
const FetchXMLFeed = require( "../UTILS/genericUtils.js" ).fetchXMLFeed;
const MakeRequest = require( "../UTILS/genericUtils.js" ).makeRequest;
const FilterUNEQResultsREDIS = require( "../UTILS/genericUtils.js" ).filterUneqResultsCOMMON;
const DX_DOI_BASE_URL = require( "../CONSTANTS/generic.js" ).DX_DOI_BASE_URL;
const SCI_HUB_BASE_URL = require( "../CONSTANTS/generic.js" ).SCI_HUB_BASE_URL;
const FRONTIERSIN_URLS = require( "../CONSTANTS/frontiersin.js" ).URLS;
const SPEC_SEARCH_TERMS = [ "autism" , "autistic" , "ASD" ];
function scanText( wText ) {
for ( var i = 0; i < SPEC_SEARCH_TERMS.length; ++i ) {
var wSTResult = wText.indexOf( SPEC_SEARCH_TERMS[ i ] );
if ( wSTResult !== -1 ) {
return true;
}
}
return false;
}
function PARSE_XML_RESULTS( wResults ) {
var finalResults = [];
for ( var i = 0; i < wResults.length; ++i ) {
var wTitle = wResults[ i ][ "title" ];
if ( wTitle ) { wTitle = wTitle.trim(); }
var wFoundInTitle = scanText( wTitle );
var wDescription = wResults[ i ][ "rss:description" ][ "#" ];
if ( wDescription ) { wDescription = wDescription.trim(); }
var wFoundInDescription = scanText( wDescription );
if ( wFoundInTitle || wFoundInDescription ) {
var wMainURL = wResults[ i ][ "link" ];
var wDOI = wMainURL.split( "https://www.frontiersin.org/articles/" )[1];
finalResults.push({
title: wTitle ,
doi: wDOI ,
doiB64: EncodeB64( wDOI ) ,
mainURL: wMainURL ,
scihubURL: wMainURL + "/pdf"
});
}
}
return finalResults;
}
function SEARCH() {
return new Promise( async function( resolve , reject ) {
try {
console.log( "\nFrontiersin.org Scan Started" );
console.log( "" );
PrintNowTime();
// 1. ) Fetch Latest RSS-Results Matching "autism-keywords"
var wResults = await map( FRONTIERSIN_URLS , wURL => FetchXMLFeed( wURL ) );
wResults = wResults.map( x => PARSE_XML_RESULTS( x ) );
wResults = [].concat.apply( [] , wResults );
console.log( wResults );
// 3.) Compare to Already 'Tracked' DOIs and Store Uneq
wResults = await FilterUNEQResultsREDIS( wResults );
// 4.) Post Results
await PostResults( wResults );
console.log( "\nFrontiersin.org Scan Finished" );
console.log( "" );
PrintNowTime();
resolve();
}
catch( error ) { console.log( error ); reject( error ); }
});
}
module.exports.search = SEARCH;