1
0
Fork 0
mirror of https://github.com/marty-oehme/scripts.git synced 2024-11-18 07:48:07 +00:00
qownnotes-scripts/weather-stats/weather-stats.qml

81 lines
2.7 KiB
QML
Raw Permalink Normal View History

2017-06-08 07:47:16 +00:00
import QtQml 2.0
import QOwnNotesTypes 1.0
/**
* This script shows current weather statistics in a "scripting label"
2017-06-08 15:43:19 +00:00
*
* The Yahoo weather api is used for fetching the weather data
* https://developer.yahoo.com/weather/
2017-06-08 07:47:16 +00:00
*/
Script {
// you have to define your registered variables so you can access them later
property string city;
property bool useFahrenheit;
// register your settings variables so the user can set them in the script settings
property variant settingsVariables: [
{
"identifier": "city",
"name": "City",
"description": "Please enter your city:",
"type": "string",
"default": "Graz",
},
{
"identifier": "useFahrenheit",
"name": "Unit",
"description": "Use Fahrenheit instead of Celsius",
"type": "boolean",
"default": false,
},
];
function init() {
script.registerLabel("weather stats")
weatherStats();
}
function weatherStats() {
var unitString = useFahrenheit ? "f" : "c"
var json = script.downloadUrlToString("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + city + "%22)%20and%20u%3D%27" + unitString + "%27&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys");
var weatherInfo = JSON.parse(json);
var temp = weatherInfo.query.results.channel.item.condition.temp
2017-06-08 15:43:19 +00:00
var tempUnit = weatherInfo.query.results.channel.units.temperature;
2017-06-08 07:47:16 +00:00
var conditionText = weatherInfo.query.results.channel.item.condition.text
2017-06-08 15:43:19 +00:00
var weatherCity = weatherInfo.query.results.channel.location.city
var windSpeed = weatherInfo.query.results.channel.wind.speed
var windUnit = weatherInfo.query.results.channel.units.speed;
2017-06-08 07:47:16 +00:00
if (!useFahrenheit) {
2017-06-08 15:43:19 +00:00
tempUnit = "°" + tempUnit;
2017-06-08 07:47:16 +00:00
}
script.setLabelText("weather stats",
2017-06-08 15:43:19 +00:00
"<table align='center' width='90%'>
2017-06-08 07:47:16 +00:00
<tr>
2017-06-08 15:43:19 +00:00
<td align='center'>
Weather in <b>" + weatherCity + "</b>: " + conditionText + " at <b>" + temp + " " + tempUnit + "</b>
(" + windSpeed + " " + windUnit + " wind)
</tb>
2017-06-08 07:47:16 +00:00
</tr>
</table>")
}
/**
* This starts a timer that triggers every 10min
*/
property QtObject timer: Timer {
interval: 600000
repeat: true
running: true
property int count: 0
onTriggered: {
weatherStats();
}
}
}