#!/usr/bin/env bun import { AtpAgent } from '@atproto/api' // Read credentials from .env const username = process.env.BSKY_USERNAME const password = process.env.BSKY_PASSWORD if (!username || !password) { console.error('Please provide BSKY_USERNAME and BSKY_PASSWORD in .env file') process.exit(1) } const agent = new AtpAgent({ service: 'https://bsky.social' }) console.log('Logging in...') await agent.login({ identifier: username, password: password }) console.log('Fetching timeline...\n') // Get the user's timeline const timeline = await agent.getTimeline({ limit: 50 }) // Filter posts that mention Chicago or ATProto const chicagoPosts = timeline.data.feed.filter(item => { const text = item.post.record?.text?.toLowerCase() || '' return text.includes('chicago') || text.includes('atproto') || text.includes('#atprotochicago') }) console.log(`Found ${chicagoPosts.length} posts mentioning Chicago/ATProto out of ${timeline.data.feed.length} recent posts:\n`) if (chicagoPosts.length === 0) { console.log('No matching posts found. Try posting with #ATProtoChicago!') } else { chicagoPosts.forEach((item, index) => { const author = item.post.author.displayName || item.post.author.handle const text = item.post.record?.text || '' const time = new Date(item.post.record?.createdAt).toLocaleString() console.log(`${index + 1}. ${author} (${time})`) console.log(` ${text.substring(0, 100)}${text.length > 100 ? '...' : ''}`) console.log(` Likes: ${item.post.likeCount || 0}, Reposts: ${item.post.repostCount || 0}`) console.log('') }) } // Bonus: Show posts with the most engagement console.log('\nšŸ“Š Bonus: Top 5 posts by engagement:') console.log('=====================================') const sortedByEngagement = timeline.data.feed .sort((a, b) => { const aEngagement = (a.post.likeCount || 0) + (a.post.repostCount || 0) * 2 const bEngagement = (b.post.likeCount || 0) + (b.post.repostCount || 0) * 2 return bEngagement - aEngagement }) .slice(0, 5) sortedByEngagement.forEach((item, index) => { const author = item.post.author.displayName || item.post.author.handle const text = item.post.record?.text || '' const engagement = (item.post.likeCount || 0) + (item.post.repostCount || 0) * 2 console.log(`${index + 1}. ${author} (score: ${engagement})`) console.log(` ${text.substring(0, 80)}${text.length > 80 ? '...' : ''}`) console.log(` Likes: ${item.post.likeCount || 0}, Reposts: ${item.post.repostCount || 0}`) console.log('') })