Last active
January 3, 2019 21:48
-
-
Save bfrancom/a014f1045e52356ddbbb926522ce1686 to your computer and use it in GitHub Desktop.
i3 conky Node js script for weather
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In .conkyrc, I have a line like: | |
{ "full_text" : "${execi 301 node /home/bob/weather.js}" , "color" : "\#ffffff" }, | |
#see result in attached image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot of i3bar: