atikin-notify-cli
Version:
A powerful daily CLI tool that shows reminders, quotes, tasks, and weather updates in your terminal. Created By: Atikin Verse.
77 lines (65 loc) • 2.74 kB
JavaScript
const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer').default;
const axios = require('axios');
const chalk = require('chalk').default;
const ora = require('ora');
const CONFIG_FILE = path.join(require('os').homedir(), '.atikinrc.json');
const QUOTES = [
"Success is not final; failure is not fatal. – Winston Churchill",
"Do one thing every day that scares you. – Eleanor Roosevelt",
"Hardships often prepare ordinary people for an extraordinary destiny. – C.S. Lewis",
"Don’t wish it were easier. Wish you were better. – Jim Rohn",
"What you get by achieving your goals is not as important as what you become by achieving your goals."
];
function getRandomQuote() {
return QUOTES[Math.floor(Math.random() * QUOTES.length)];
}
async function getWeather(city) {
const apiKey = 'cb5770a6be470ae192439e9d60ebb892'; // Free OpenWeather API Key
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&units=metric&appid=${apiKey}`;
try {
const spinner = ora('Fetching weather...').start();
const response = await axios.get(url);
spinner.succeed();
const { temp } = response.data.main;
const { description } = response.data.weather[0];
return `${temp}°C, ${description}`;
} catch (error) {
return "Weather info unavailable";
}
}
async function main() {
console.clear();
console.log(chalk.blueBright.bold('🌞 Good Day from AtikinNotify CLI!'));
let config = {
username: "User",
city: "Delhi",
tasks: ["Check email", "Drink water", "Code something cool"],
showWeather: false
};
if (fs.existsSync(CONFIG_FILE)) {
const content = fs.readFileSync(CONFIG_FILE);
config = JSON.parse(content);
} else {
const answers = await inquirer.prompt([
{ type: 'input', name: 'username', message: 'Enter your name:' },
{ type: 'input', name: 'city', message: 'Your city for weather:' },
{ type: 'confirm', name: 'showWeather', message: 'Show weather info?' },
]);
config = { ...config, ...answers };
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
}
console.log(`👋 Hello, ${chalk.green(config.username)}!`);
console.log("📝 Today's Tasks:");
config.tasks.forEach((task) => {
console.log(` - [ ] ${task}`);
});
console.log(`\n💡 Quote of the Day:\n "${chalk.yellow(getRandomQuote())}"`);
if (config.showWeather) {
const weather = await getWeather(config.city);
console.log(`\n🌤 Weather in ${config.city}: ${chalk.cyan(weather)}`);
}
}
main();