-
Notifications
You must be signed in to change notification settings - Fork 1
/
ehp-niehs-nih.js
94 lines (81 loc) · 2.76 KB
/
ehp-niehs-nih.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
85
86
87
88
89
90
91
92
93
94
const cheerio = require( "cheerio" );
const PostResults = require( "../UTILS/mastadonManager.js" ).formatPapersAndPost;
const PrintNowTime = require( "../UTILS/genericUtils.js" ).printNowTime;
const EncodeB64 = require( "../UTILS/genericUtils.js" ).encodeBase64;
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;
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
function PARSE_SEARCH_RESULTS( wBody ) {
try { var $ = cheerio.load( wBody ); }
catch( err ) { return "fail"; }
var wTitles = [];
var wLinks = [];
var wDOIS = [];
$( ".searchresults" ).each( function() {
var x1 = $( this ).children();
if ( x1 ) {
var x1_Title = $( x1[ 0 ] ).text();
var x1_Link = $( x1[ 0 ] ).attr( "href" );
if ( x1_Title ) { x1_Title = x1_Title.trim(); x1_Title = x1_Title.replace(/ +(?= )/g,''); wTitles.push( x1_Title ); }
if ( x1_Link ) { wLinks.push( x1_Link ); }
}
});
$( ".searchcitation" ).each( function() {
var x1 = $( this ).text();
if ( x1 ) {
x1 = x1.trim();
if ( x1.indexOf( "doi:" ) !== -1 ) {
x1 = x1.split( "doi:" )[ 1 ];
x1 = x1.ltrim();
wDOIS.push( x1 );
}
}
});
var finalResults = [];
if ( wTitles.length === wLinks.length ) {
for ( var i = 0; i < wTitles.length; ++i ) {
var x1_OBJ = {
title: wTitles[ i ] ,
mainURL: wLinks[ i ]
};
if ( wDOIS[ i ] !== undefined ) {
x1_OBJ[ "doi" ] = wDOIS[ i ];
x1_OBJ[ "doiB64" ] = EncodeB64( wDOIS[ i ] );
x1_OBJ[ "scihubURL" ] = SCI_HUB_BASE_URL + wDOIS[ i ];
}
finalResults.push( x1_OBJ );
}
}
return finalResults;
}
const EHP_NIEHS_NIH_SEARCH_URL = "https://ehp.niehs.nih.gov/search-ehp/?fwp_title_search_facet=autism&fwp_abstract_search_facet=autism&fwp_sort=date_desc";
function SEARCH() {
return new Promise( async function( resolve , reject ) {
try {
console.log( "\nEHP.NIEHS.NIH.gov Scan Started" );
console.log( "" );
PrintNowTime();
// 1.) Search for Results
var wBody = await MakeRequest( EHP_NIEHS_NIH_SEARCH_URL );
// 2.) Parse Results
var wResults = PARSE_SEARCH_RESULTS( wBody );
// 3.) Compare to Already 'Tracked' DOIs and Store Uneq
wResults = await FilterUNEQResultsREDIS( wResults );
// 4.) Post Results
await PostResults( wResults );
console.log( "\nEHP.NIEHS.NIH.gov Scan Finished" );
console.log( "" );
PrintNowTime();
resolve();
}
catch( error ) { console.log( error ); reject( error ); }
});
}
module.exports.search = SEARCH;