|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const https = require("https"); |
| 4 | +const readline = require("readline"); |
| 5 | + |
| 6 | +const rl = readline.createInterface({ |
| 7 | + input: process.stdin, |
| 8 | + output: process.stdout, |
| 9 | +}); |
| 10 | + |
| 11 | +const API_URL = "https://pulkitxm.com/api/profile"; |
| 12 | + |
| 13 | +console.clear(); |
| 14 | + |
| 15 | +console.log("\n=== Pulkit's Profile ==="); |
| 16 | +console.log("Data source: " + API_URL + "\n"); |
| 17 | + |
| 18 | +function formatDate(dateString) { |
| 19 | + if (!dateString) return "Present"; |
| 20 | + const date = new Date(dateString); |
| 21 | + return date.toLocaleDateString("en-US", { year: "numeric", month: "short" }); |
| 22 | +} |
| 23 | + |
| 24 | +function fetchProfileData() { |
| 25 | + return new Promise((resolve, reject) => { |
| 26 | + console.log("Fetching profile data..."); |
| 27 | + |
| 28 | + https |
| 29 | + .get(API_URL, (res) => { |
| 30 | + let data = ""; |
| 31 | + |
| 32 | + res.on("data", (chunk) => { |
| 33 | + data += chunk; |
| 34 | + }); |
| 35 | + |
| 36 | + res.on("end", () => { |
| 37 | + try { |
| 38 | + const profileData = JSON.parse(data); |
| 39 | + console.log("Data loaded successfully!\n"); |
| 40 | + resolve(profileData); |
| 41 | + } catch (error) { |
| 42 | + reject(new Error("Error parsing profile data")); |
| 43 | + } |
| 44 | + }); |
| 45 | + }) |
| 46 | + .on("error", (err) => { |
| 47 | + reject(new Error(`Error fetching profile data: ${err.message}`)); |
| 48 | + }); |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +function displayBasicInfo(profile) { |
| 53 | + console.clear(); |
| 54 | + console.log("\n=== Basic Information ===\n"); |
| 55 | + console.log(`Name: ${profile.name}`); |
| 56 | + console.log(`Title: ${profile.caption}`); |
| 57 | + console.log(`Email: ${profile.email}`); |
| 58 | + console.log(`\nLinks:`); |
| 59 | + console.log(`Resume: ${profile.resumeLink}`); |
| 60 | + console.log(`GitHub: ${profile.links.github}`); |
| 61 | + console.log(`LinkedIn: ${profile.links.linkedin}`); |
| 62 | + console.log(`Twitter: ${profile.links.twitter}`); |
| 63 | + if (profile.links.blogs) { |
| 64 | + console.log(`Blog: ${profile.links.blogs}`); |
| 65 | + } |
| 66 | + return showMainMenu(profile); |
| 67 | +} |
| 68 | + |
| 69 | +function displayExperience(profile) { |
| 70 | + console.clear(); |
| 71 | + console.log("\n=== Experience ===\n"); |
| 72 | + |
| 73 | + profile.experience.forEach((exp, index) => { |
| 74 | + console.log(`${index + 1}. ${exp.position} at ${exp.companyName}`); |
| 75 | + console.log( |
| 76 | + ` ${formatDate(exp.startDate)} - ${formatDate(exp.endDate)} | ${ |
| 77 | + exp.type |
| 78 | + } | ${exp.location}` |
| 79 | + ); |
| 80 | + if (exp.desc) { |
| 81 | + console.log(` ${exp.desc}`); |
| 82 | + } |
| 83 | + console.log(""); |
| 84 | + }); |
| 85 | + |
| 86 | + return showMainMenu(profile); |
| 87 | +} |
| 88 | + |
| 89 | +function displayProjects(profile) { |
| 90 | + console.clear(); |
| 91 | + console.log("\n=== Projects ===\n"); |
| 92 | + |
| 93 | + profile.projects.forEach((project, index) => { |
| 94 | + console.log(`${index + 1}. ${project.name}`); |
| 95 | + console.log(` Description: ${project.tagline || "No description"}`); |
| 96 | + console.log(` URL: ${project.url}`); |
| 97 | + console.log(""); |
| 98 | + }); |
| 99 | + |
| 100 | + return showMainMenu(profile); |
| 101 | +} |
| 102 | + |
| 103 | +function displaySkills(profile) { |
| 104 | + console.clear(); |
| 105 | + console.log("\n=== Skills ===\n"); |
| 106 | + |
| 107 | + Object.entries(profile.skills).forEach(([category, skillList]) => { |
| 108 | + console.log(`${category}:`); |
| 109 | + console.log(` ${skillList.join(", ")}`); |
| 110 | + console.log(""); |
| 111 | + }); |
| 112 | + |
| 113 | + return showMainMenu(profile); |
| 114 | +} |
| 115 | + |
| 116 | +function displayCertifications(profile) { |
| 117 | + console.clear(); |
| 118 | + console.log("\n=== Certifications ===\n"); |
| 119 | + |
| 120 | + profile.certifications.forEach((cert, index) => { |
| 121 | + console.log(`${index + 1}. ${cert.name}`); |
| 122 | + console.log( |
| 123 | + ` Issued by: ${cert.issuedBy.name} (${formatDate(cert.issuedAt)})` |
| 124 | + ); |
| 125 | + console.log(` Verify: ${cert.verifyLink}`); |
| 126 | + console.log(""); |
| 127 | + }); |
| 128 | + |
| 129 | + return showMainMenu(profile); |
| 130 | +} |
| 131 | + |
| 132 | +function displayContributions(profile) { |
| 133 | + console.clear(); |
| 134 | + console.log("\n=== GitHub Contributions ===\n"); |
| 135 | + |
| 136 | + const recentYears = profile.contributions.slice(-2); |
| 137 | + |
| 138 | + recentYears.forEach((yearData) => { |
| 139 | + console.log( |
| 140 | + `${yearData.year}: ${yearData.contributions.totalContributions} contributions` |
| 141 | + ); |
| 142 | + |
| 143 | + const months = yearData.contributions.months; |
| 144 | + months.forEach((month) => { |
| 145 | + const totalInMonth = month.days.reduce( |
| 146 | + (sum, day) => sum + day.contributionCount, |
| 147 | + 0 |
| 148 | + ); |
| 149 | + if (totalInMonth > 0) { |
| 150 | + const barLength = Math.min(Math.floor(totalInMonth / 5), 30); |
| 151 | + console.log( |
| 152 | + ` ${month.month}: ${"#".repeat(barLength)} (${totalInMonth})` |
| 153 | + ); |
| 154 | + } |
| 155 | + }); |
| 156 | + console.log(""); |
| 157 | + }); |
| 158 | + |
| 159 | + return showMainMenu(profile); |
| 160 | +} |
| 161 | + |
| 162 | +function showMainMenu(profile) { |
| 163 | + console.log("\nWhat would you like to see?"); |
| 164 | + console.log("1. Basic Information"); |
| 165 | + console.log("2. Experience"); |
| 166 | + console.log("3. Projects"); |
| 167 | + console.log("4. Skills"); |
| 168 | + console.log("5. Certifications"); |
| 169 | + console.log("6. GitHub Contributions"); |
| 170 | + console.log("7. Exit"); |
| 171 | + |
| 172 | + rl.question("\nEnter your choice (1-7): ", (choice) => { |
| 173 | + switch (choice) { |
| 174 | + case "1": |
| 175 | + return displayBasicInfo(profile); |
| 176 | + case "2": |
| 177 | + return displayExperience(profile); |
| 178 | + case "3": |
| 179 | + return displayProjects(profile); |
| 180 | + case "4": |
| 181 | + return displaySkills(profile); |
| 182 | + case "5": |
| 183 | + return displayCertifications(profile); |
| 184 | + case "6": |
| 185 | + return displayContributions(profile); |
| 186 | + case "7": |
| 187 | + console.log("\nThanks for checking out my profile! Goodbye!"); |
| 188 | + rl.close(); |
| 189 | + return; |
| 190 | + default: |
| 191 | + console.log("\nInvalid choice. Please enter a number between 1 and 7."); |
| 192 | + return showMainMenu(profile); |
| 193 | + } |
| 194 | + }); |
| 195 | +} |
| 196 | + |
| 197 | +async function main() { |
| 198 | + try { |
| 199 | + const profile = await fetchProfileData(); |
| 200 | + showMainMenu(profile); |
| 201 | + } catch (error) { |
| 202 | + console.error(`\nError: ${error.message}`); |
| 203 | + rl.close(); |
| 204 | + } |
| 205 | +} |
| 206 | + |
| 207 | +main(); |
0 commit comments