@pratiksha90/financial-data-extractors
Version:
Utilities for extracting financial data from various economic calendar websites
91 lines (90 loc) • 3.98 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isInvestingCalendar = isInvestingCalendar;
exports.extractInvestingData = extractInvestingData;
/**
* Check if the current page is Investing.com calendar
*/
function isInvestingCalendar(url) {
return url.includes('investing.com/economic-calendar');
}
/**
* Extract Investing.com calendar data
*/
function extractInvestingData(options) {
const { document } = options;
const url = document.URL || '';
const events = [];
try {
// Get the calendar table
const calendarTable = document.getElementById('economicCalendarData');
if (!calendarTable) {
return { metadata: { title: "Investing.com Calendar", source: url, extractedAt: new Date().toISOString() }, events: [] };
}
// Get all event rows
const eventRows = calendarTable.querySelectorAll('tbody tr[id^="eventRowId_"]');
let currentDate = '';
// Process each row
eventRows.forEach(row => {
var _a, _b, _c, _d, _e, _f, _g;
// Check if this is a date separator row
const isDateRow = row.classList.contains('theDay');
if (isDateRow) {
currentDate = ((_a = row.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
return;
}
// Get time
const timeCell = row.querySelector('td.time');
const time = timeCell ? ((_b = timeCell.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '' : '';
// Get country
const countryCell = row.querySelector('td.flagCur');
const country = countryCell ? ((_c = countryCell.querySelector('span')) === null || _c === void 0 ? void 0 : _c.title) || '' : '';
// Get event name
const eventCell = row.querySelector('td.event');
const eventName = eventCell ? ((_d = eventCell.textContent) === null || _d === void 0 ? void 0 : _d.trim()) || '' : '';
// Get impact
const impactCell = row.querySelector('td.sentiment');
const impactSpans = impactCell ? impactCell.querySelectorAll('i.grayFullBullishIcon, i.grayFullBearishIcon') : [];
const impact = impactSpans.length === 3 ? 'High' : impactSpans.length === 2 ? 'Medium' : 'Low';
// Get values
const actualCell = row.querySelector('td.act');
const actual = actualCell ? ((_e = actualCell.textContent) === null || _e === void 0 ? void 0 : _e.trim()) || '' : '';
const forecastCell = row.querySelector('td.fore');
const forecast = forecastCell ? ((_f = forecastCell.textContent) === null || _f === void 0 ? void 0 : _f.trim()) || '' : '';
const previousCell = row.querySelector('td.prev');
const previous = previousCell ? ((_g = previousCell.textContent) === null || _g === void 0 ? void 0 : _g.trim()) || '' : '';
if (eventName) {
events.push({
date: currentDate,
time: time,
country: country,
event: eventName,
impact: impact,
actual: actual,
forecast: forecast,
previous: previous
});
}
});
return {
metadata: {
title: "Investing.com Economic Calendar",
source: url,
extractedAt: new Date().toISOString(),
totalEvents: events.length
},
events: events
};
}
catch (error) {
return {
metadata: {
title: "Investing.com Economic Calendar",
source: url,
extractedAt: new Date().toISOString(),
error: "Failed to extract calendar data"
},
events: []
};
}
}