google trends

Signed-off-by: ale <ale@manalejandro.com>
Este commit está contenido en:
ale
2025-06-08 06:54:29 +02:00
padre c21e4d891a
commit 29db5a08c0
Se han modificado 7 ficheros con 118 adiciones y 450 borrados

107
index.js
Ver fichero

@@ -392,33 +392,13 @@ async function searchVideos(query, limit = 5) {
}
// Google Trends function to get real-time trending topics
// Function to get trending topics from multiple sources
// Function to get trending topics from Reddit
async function getTrends(country = 'US') {
try {
console.log(`📊 Fetching trends for ${country}...`);
console.log(`📊 Fetching Reddit trends...`);
// Try Reddit trending first (most reliable)
try {
const redditTrends = await getRedditTrending();
if (redditTrends && Object.keys(redditTrends).length > 0) {
return redditTrends;
}
} catch (error) {
console.log('Reddit trending failed, trying news...');
}
// Fallback to news headlines
try {
const newsTrends = await getNewsHeadlines(country);
if (newsTrends && Object.keys(newsTrends).length > 0) {
return newsTrends;
}
} catch (error) {
console.log('News headlines failed, using mock data...');
}
// Final fallback - mock trending data
return getMockTrends(country);
const redditTrends = await getRedditTrending();
return redditTrends;
} catch (error) {
console.error('❌ Error fetching trends:', error.message);
@@ -462,85 +442,6 @@ async function getRedditTrending() {
}
}
// Get news headlines as trending topics
async function getNewsHeadlines(country) {
try {
// Map country codes to news regions
const countryMap = {
'US': 'us',
'GB': 'gb',
'FR': 'fr',
'DE': 'de',
'ES': 'es',
'JP': 'jp',
'BR': 'br'
};
const region = countryMap[country] || 'us';
// Using a free news API alternative
const response = await axios.get(`https://saurav.tech/NewsAPI/top-headlines/category/general/${region}.json`, {
timeout: 10000
});
const articles = response.data.articles.slice(0, 12);
const groupedTrends = {};
articles.forEach(article => {
const source = article.source?.name || 'News Source';
if (!groupedTrends[source]) {
groupedTrends[source] = [];
}
groupedTrends[source].push({
title: article.title,
traffic: 'Breaking News',
url: article.url,
snippet: article.description || 'Latest news headline'
});
});
return groupedTrends;
} catch (error) {
console.error('News headlines error:', error.message);
throw error;
}
}
// Mock trending data as final fallback
function getMockTrends(country) {
const mockData = {
'TechCrunch': [
{
title: 'AI Development Trends 2024',
traffic: '50K+ searches',
url: 'https://techcrunch.com',
snippet: 'Latest developments in artificial intelligence and machine learning'
}
],
'BBC News': [
{
title: 'Global Market Updates',
traffic: '25K+ searches',
url: 'https://bbc.com/news',
snippet: 'Latest financial and economic news from around the world'
}
],
'Reddit Discussions': [
{
title: 'Technology Innovations',
traffic: '15K+ upvotes',
url: 'https://reddit.com/r/technology',
snippet: 'Community discussions about emerging technologies'
}
]
};
console.log(`📋 Using mock trends data for ${country}`);
return mockData;
}
// Bitcoin transaction monitoring functions
async function initBitcoinMonitoring() {
try {