@towles/tool 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +85 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -121,7 +121,7 @@ async function loadSettings() {
|
|
|
121
121
|
);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
const version = "0.0.
|
|
124
|
+
const version = "0.0.18";
|
|
125
125
|
|
|
126
126
|
const JOURNAL_TYPES = {
|
|
127
127
|
DAILY_NOTES: "daily-notes",
|
|
@@ -208,6 +208,14 @@ async function parseArguments(argv) {
|
|
|
208
208
|
parsedResult = { command: "config", args: {} };
|
|
209
209
|
}
|
|
210
210
|
);
|
|
211
|
+
parser.command(
|
|
212
|
+
["weather", "w"],
|
|
213
|
+
"Show current weather for Cincinnati, OH",
|
|
214
|
+
{},
|
|
215
|
+
() => {
|
|
216
|
+
parsedResult = { command: "weather", args: {} };
|
|
217
|
+
}
|
|
218
|
+
);
|
|
211
219
|
await parser.parse();
|
|
212
220
|
if (!parsedResult) {
|
|
213
221
|
throw new Error("No command was parsed");
|
|
@@ -668,6 +676,79 @@ async function githubBranchCommand(context, args) {
|
|
|
668
676
|
}
|
|
669
677
|
}
|
|
670
678
|
|
|
679
|
+
const CINCINNATI_LATITUDE = 39.1031;
|
|
680
|
+
const CINCINNATI_LONGITUDE = -84.512;
|
|
681
|
+
const WEATHER_DESCRIPTIONS = {
|
|
682
|
+
0: { description: "Clear sky", emoji: "\u2600\uFE0F" },
|
|
683
|
+
1: { description: "Mainly clear", emoji: "\u{1F324}\uFE0F" },
|
|
684
|
+
2: { description: "Partly cloudy", emoji: "\u26C5" },
|
|
685
|
+
3: { description: "Overcast", emoji: "\u2601\uFE0F" },
|
|
686
|
+
45: { description: "Fog", emoji: "\u{1F32B}\uFE0F" },
|
|
687
|
+
48: { description: "Depositing rime fog", emoji: "\u{1F32B}\uFE0F" },
|
|
688
|
+
51: { description: "Light drizzle", emoji: "\u{1F326}\uFE0F" },
|
|
689
|
+
53: { description: "Moderate drizzle", emoji: "\u{1F326}\uFE0F" },
|
|
690
|
+
55: { description: "Dense drizzle", emoji: "\u{1F327}\uFE0F" },
|
|
691
|
+
56: { description: "Light freezing drizzle", emoji: "\u{1F328}\uFE0F" },
|
|
692
|
+
57: { description: "Dense freezing drizzle", emoji: "\u{1F328}\uFE0F" },
|
|
693
|
+
61: { description: "Slight rain", emoji: "\u{1F327}\uFE0F" },
|
|
694
|
+
63: { description: "Moderate rain", emoji: "\u{1F327}\uFE0F" },
|
|
695
|
+
65: { description: "Heavy rain", emoji: "\u{1F327}\uFE0F" },
|
|
696
|
+
66: { description: "Light freezing rain", emoji: "\u{1F328}\uFE0F" },
|
|
697
|
+
67: { description: "Heavy freezing rain", emoji: "\u{1F328}\uFE0F" },
|
|
698
|
+
71: { description: "Slight snow fall", emoji: "\u{1F328}\uFE0F" },
|
|
699
|
+
73: { description: "Moderate snow fall", emoji: "\u2744\uFE0F" },
|
|
700
|
+
75: { description: "Heavy snow fall", emoji: "\u2744\uFE0F" },
|
|
701
|
+
77: { description: "Snow grains", emoji: "\u{1F328}\uFE0F" },
|
|
702
|
+
80: { description: "Slight rain showers", emoji: "\u{1F326}\uFE0F" },
|
|
703
|
+
81: { description: "Moderate rain showers", emoji: "\u{1F327}\uFE0F" },
|
|
704
|
+
82: { description: "Violent rain showers", emoji: "\u26C8\uFE0F" },
|
|
705
|
+
85: { description: "Slight snow showers", emoji: "\u{1F328}\uFE0F" },
|
|
706
|
+
86: { description: "Heavy snow showers", emoji: "\u2744\uFE0F" },
|
|
707
|
+
95: { description: "Thunderstorm", emoji: "\u26C8\uFE0F" },
|
|
708
|
+
96: { description: "Thunderstorm with slight hail", emoji: "\u26C8\uFE0F" },
|
|
709
|
+
99: { description: "Thunderstorm with heavy hail", emoji: "\u26C8\uFE0F" }
|
|
710
|
+
};
|
|
711
|
+
function getWindDirection(degrees) {
|
|
712
|
+
const directions = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
|
|
713
|
+
const index = Math.round(degrees / 22.5) % 16;
|
|
714
|
+
return directions[index];
|
|
715
|
+
}
|
|
716
|
+
function formatWeatherData(data) {
|
|
717
|
+
const { current_weather: weather, current_weather_units: units } = data;
|
|
718
|
+
const weatherInfo = WEATHER_DESCRIPTIONS[weather.weathercode] || {
|
|
719
|
+
description: "Unknown",
|
|
720
|
+
emoji: "\u2753"
|
|
721
|
+
};
|
|
722
|
+
const windDirection = getWindDirection(weather.winddirection);
|
|
723
|
+
const timeOfDay = weather.is_day ? "Day" : "Night";
|
|
724
|
+
consola.info("\u{1F30E} Current Weather in Cincinnati, OH");
|
|
725
|
+
consola.log("");
|
|
726
|
+
consola.log(`${weatherInfo.emoji} ${weatherInfo.description}`);
|
|
727
|
+
consola.log(`\u{1F321}\uFE0F Temperature: ${weather.temperature}${units.temperature}`);
|
|
728
|
+
consola.log(`\u{1F4A8} Wind: ${weather.windspeed} ${units.windspeed} ${windDirection}`);
|
|
729
|
+
consola.log(`\u{1F550} Time: ${new Date(weather.time).toLocaleTimeString()} (${timeOfDay})`);
|
|
730
|
+
}
|
|
731
|
+
async function weatherCommand(context) {
|
|
732
|
+
try {
|
|
733
|
+
consola.start("Fetching current weather for Cincinnati...");
|
|
734
|
+
const url = `https://api.open-meteo.com/v1/forecast?latitude=${CINCINNATI_LATITUDE}&longitude=${CINCINNATI_LONGITUDE}¤t_weather=true&temperature_unit=fahrenheit&windspeed_unit=mph&timezone=America/New_York`;
|
|
735
|
+
const response = await fetch(url);
|
|
736
|
+
if (!response.ok) {
|
|
737
|
+
throw new Error(`Weather API request failed: ${response.status} ${response.statusText}`);
|
|
738
|
+
}
|
|
739
|
+
const data = await response.json();
|
|
740
|
+
if (!data.current_weather) {
|
|
741
|
+
throw new Error("No weather data received from API");
|
|
742
|
+
}
|
|
743
|
+
consola.success("Weather data retrieved successfully!");
|
|
744
|
+
consola.log("");
|
|
745
|
+
formatWeatherData(data);
|
|
746
|
+
} catch (error) {
|
|
747
|
+
consola.error("Failed to fetch weather data:", error instanceof Error ? error.message : String(error));
|
|
748
|
+
process.exit(1);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
671
752
|
async function executeCommand(parsedArgs, context) {
|
|
672
753
|
switch (parsedArgs.command) {
|
|
673
754
|
case "journal": {
|
|
@@ -683,6 +764,9 @@ async function executeCommand(parsedArgs, context) {
|
|
|
683
764
|
case "config":
|
|
684
765
|
await configCommand(context);
|
|
685
766
|
break;
|
|
767
|
+
case "weather":
|
|
768
|
+
await weatherCommand();
|
|
769
|
+
break;
|
|
686
770
|
default:
|
|
687
771
|
throw new Error(`Unknown command: ${parsedArgs.command}`);
|
|
688
772
|
}
|
package/package.json
CHANGED