Cumfiesta.24.06.16.ryan.reid.the.rise.of.the.cu... -
# backend/services/trending_algorithm.py from datetime import datetime, timezone import math def calculate_trend_score(content, current_time): hours_since_publish = (current_time - content.published_at).total_seconds() / 3600 hours_since_decay_start = (current_time - content.decay_started_at).total_seconds() / 3600
# Gravity factor (newer content gets boost) gravity = 1.5 if hours_since_publish < 24 else 1.8
# Apply recency bonus if hours_since_publish < 2: score *= 1.5 return round(score, 6) // GET /api/trending/feed router.get('/feed', async (req, res) => { const limit = 20, offset = 0, contentType, category = req.query; const whereClause = {}; if (contentType) whereClause.contentType = contentType; if (category) whereClause.category = category;
// Trigger async recalc of trendScore queue.add('recalc-trending', contentId ); CumFiesta.24.06.16.Ryan.Reid.The.Rise.Of.The.Cu...
@@index([trendScore(sort: Desc)]) @@index([contentType, category])
const fetchTrending = async () => setLoading(true); const res = await fetch( /api/trending/feed?limit=15&offset=$page * 15 ); const newItems = await res.json(); setItems(prev => [...prev, ...newItems.data]); setLoading(false); ;
# scraper/entertainment_aggregator.py import feedparser from selenium import webdriver def fetch_reddit_trending(): # r/all trending in entertainment reddit_url = "https://www.reddit.com/r/entertainment/top.json?t=day&limit=25" # Use praw library or requests with auth return posts # backend/services/trending_algorithm
useEffect(() => fetchTrending(); , [page]);
// POST /api/trending/:id/interact router.post('/:id/interact', async (req, res) => const type = req.body; // 'like', 'share', 'view' const contentId = req.params.id;
Simplified implementation:
enum ContentType VIDEO MEME ARTICLE TRAILER
// Add user-specific interaction status if (req.user) for (const item of trendingContent) item.userLiked = await prisma.userLike.findUnique( where: userId_contentId: userId: req.user.id, contentId: item.id ) !== null;
def fetch_youtube_trending(): youtube_api_key = os.getenv("YOUTUBE_API_KEY") url = f"https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics&chart=mostPopular®ionCode=US&videoCategoryId=10&key=youtube_api_key" # Category 10 = Music, 24 = Entertainment return videos timezone import math def calculate_trend_score(content
def fetch_twitter_trending(): # Use Tweepy to get trending topics + top media tweets client.get_trends_place(1) # Worldwide For "live" trending updates, push new trending items to connected clients: