Skip to content

Instantly share code, notes, and snippets.

@bfrancom
Last active January 3, 2019 21:48
Show Gist options
  • Save bfrancom/a014f1045e52356ddbbb926522ce1686 to your computer and use it in GitHub Desktop.
Save bfrancom/a014f1045e52356ddbbb926522ce1686 to your computer and use it in GitHub Desktop.
i3 conky Node js script for weather
#In .conkyrc, I have a line like:
{ "full_text" : "${execi 301 node /home/bob/weather.js}" , "color" : "\#ffffff" },
#see result in attached image
require('dns').resolve('www.google.com', function(err) {
if (err) {
console.log("No connection");
} else {
'use strict';
var request = require('request');
//Go get you an api code from api.darksky.net
var url = 'https://api.darksky.net/forecast/<api-code>/40.7608,-111.8910';
request.get({
url: url,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, data) => {
if (err) {
console.log('Error:', err);
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
// data is already parsed as JSON:
var summary = (data.currently.summary);
var temp_suffix = (data.currently.temperature + "°F", data.currently.summary);
if (summary === "Cloudy" || summary === "Partly Cloudy" || summary === "Mostly Cloudy" || summary === "Light Rain" || summary === "Ov
ercast") {
console.log("☁" + " " + data.currently.temperature + "°F", data.currently.summary);
}
else if (summary === "Rain" || summary === "Heavy Rain" || summary === "Light Rain") {
console.log("☔" + " " + data.currently.temperature + " F", data.currently.summary);
}
else if (summary === "Sunny") {
console.log("☼" + " " + data.currently.temperature + "°F", data.currently.summary);
}
else if (summary === "Light Snow" || summary === "Flurries" || summary === "Snow") {
console.log("❄" + " " + data.currently.temperature + "°F", data.currently.summary);
}
else if (summary === "Clear") {
console.log("" + " " + data.currently.temperature + "°F", data.currently.summary);
}
else {
//console.log("your mom! Look at the code");
console.log("wingnut" + " " + data.currently.temperature + "°F", "need this in your code:" + data.currently.summary);
}
}
});
}
});
@bfrancom
Copy link
Author

bfrancom commented Feb 16, 2017

Screenshot of i3bar:
2017-03-03_14_41_46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment