Skip to content

Instantly share code, notes, and snippets.

@jondcallahan
Created April 15, 2021 18:29
Show Gist options
  • Save jondcallahan/b5e459775149fbf2ec77c217b06e0577 to your computer and use it in GitHub Desktop.
Save jondcallahan/b5e459775149fbf2ec77c217b06e0577 to your computer and use it in GitHub Desktop.
#!/usr/bin/env deno run --allow-net=openweathermap.org
// Parameters
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Weather
// @raycast.mode inline
// @raycast.refreshTime 5m
// Optional parameters:
// @raycast.icon 🌎
// Documentation:
// @raycast.author Jon Callahan
// @raycast.description Weather
const API_KEY = ""; // Get this from openweathermap.org
const LOCATION = "5400075"; // Get this from openweathermap.org
fetch(
`https://openweathermap.org/data/2.5/weather?id=${LOCATION}&units=imperial&appid=${API_KEY}`,
).then(async (res) => {
if (res.ok) {
const { main: { temp }, weather: [{ description }], name } = await res
.json();
let formattedDesc = description.charAt(0).toUpperCase() +
description.slice(1);
if (formattedDesc.toLowerCase().includes("cloud")) {
formattedDesc += " ☁️";
}
if (
formattedDesc.toLowerCase().includes("sun") ||
formattedDesc.toLowerCase().includes("clear sky") ||
formattedDesc.toLowerCase().includes("few clouds")
) {
formattedDesc += " ☀️";
}
if (formattedDesc.toLowerCase().includes("rain")) {
formattedDesc += " 🌧️";
}
if (formattedDesc.toLowerCase().includes("wind")) {
formattedDesc += " 🌬️";
}
if (formattedDesc.toLowerCase().includes("snow")) {
formattedDesc += " ⛄";
}
console.log(
`${name}: ${Math.round(temp)}º - ${formattedDesc}`,
);
} else {
console.log(res.statusText);
}
}).catch((err) => {
console.error(err.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment