forked from k12club/investing-com-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
31 lines (29 loc) · 802 Bytes
/
functions.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
/**
* Map the Investing array response
* @param {Array} array Array of data returned from Investing website
* @return {Array} An array of objects with date and value properties
*/
function mapResponse(array = []) {
return array.map((item) => ({
date: item[0], // date
value: item[1], // open
price_open: item[1],
price_high: item[2],
price_low: item[3],
price_close: item[4],
}));
}
/**
* Get JSON response from Investing APIs
* @param {*} page puppeteer page
* @return {Object} JSON response from Investing
*/
async function getJsonContent(page) {
// eslint-disable-next-line no-undef
const content = await page.evaluate(() => document.querySelector('body').textContent);
return JSON.parse(content);
}
module.exports = {
mapResponse,
getJsonContent,
};