const axios = require('axios'); const cheerio = require('cheerio'); class GitHubStalker { constructor() { this.client = axios.create({ headers: { 'User-Agent': 'Mozilla/5.0 (Linux; Android 10; Mobile) AppleWebKit/537.36' }, timeout: 30000 }); } async stalk(username) { try { const userResponse = await this.client.get(`https://api.github.com/users/${username}`); const userData = userResponse.data; const htmlResponse = await this.client.get(`https://github.com/${username}`); const $ = cheerio.load(htmlResponse.data); const pinnedRepos = []; $('.pinned-item-list-item').each((index, element) => { const $repo = $(element); const name = $repo.find('.repo').text().trim(); const description = $repo.find('.pinned-item-desc').text().trim(); const url = `https://github.com${$repo.find('a').attr('href')}`; const stars = $repo.find('[aria-label="stars"]').text().trim() || '0'; const forks = $repo.find('[aria-label="forks"]').text().trim() || '0'; const language = $repo.find('[itemprop="programmingLanguage"]').text().trim(); if (name) { pinnedRepos.push({ name: name, description: description, url: url, stars: parseInt(stars.replace(',', '')) || 0, forks: parseInt(forks.replace(',', '')) || 0, language: language }); } }); const contributionsText = $('.js-yearly-contributions h2').text(); const contributionsMatch = contributionsText.match(/(\d+,?\d*)\s+contributions/); return { success: true, profile: { username: userData.login, name: userData.name || '', avatar: userData.avatar_url, bio: userData.bio || '', company: userData.company || '', location: userData.location || '', website: userData.blog || '', followers: userData.followers, following: userData.following, public_repos: userData.public_repos, public_gists: userData.public_gists, created_at: userData.created_at, profile_url: userData.html_url }, pinned_repos: pinnedRepos, contributions: contributionsMatch ? contributionsMatch[1] : '0' }; } catch (error) { if (error.response?.status === 404) { throw new Error('User not found'); } throw new Error(`GitHub stalk failed: ${error.message}`); } } } async function main() { const username = process.argv[2]; if (!username) { console.log(JSON.stringify({ error: "Username required", usage: "node gh.js ", examples: [ "node gh.js torvalds", "node gh.js gustavoguanabara" ] })); process.exit(1); } const stalker = new GitHubStalker(); try { const result = await stalker.stalk(username); console.log(JSON.stringify(result, null, 2)); } catch (error) { console.log(JSON.stringify({ error: error.message }, null, 2)); process.exit(1); } } if (require.main === module) { main(); }