mirror of
https://github.com/marty-oehme/scripts.git
synced 2024-12-22 07:58:08 +00:00
added weather stats script
This commit is contained in:
parent
0152ba7cb8
commit
e880663c10
2 changed files with 82 additions and 0 deletions
9
weather-stats/info.json
Normal file
9
weather-stats/info.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "Weather stats",
|
||||||
|
"identifier": "weather-stats",
|
||||||
|
"script": "weather-stats.qml",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"minAppVersion": "17.06.4",
|
||||||
|
"authors": ["@pbek"],
|
||||||
|
"description" : "This script shows the current weather in the <i>Scripting widget</i>. You can configure the city in the <i>Scripting Settings</i>. The Yahoo weather service is used to fetch the weather. The information is updated every 10min."
|
||||||
|
}
|
73
weather-stats/weather-stats.qml
Normal file
73
weather-stats/weather-stats.qml
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
import QtQml 2.0
|
||||||
|
import QOwnNotesTypes 1.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This script shows current weather statistics in a "scripting label"
|
||||||
|
*/
|
||||||
|
|
||||||
|
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
|
||||||
|
// use this property if you don't need
|
||||||
|
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() {
|
||||||
|
script.log(useFahrenheit);
|
||||||
|
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
|
||||||
|
var unit = weatherInfo.query.results.channel.units.temperature;
|
||||||
|
var conditionText = weatherInfo.query.results.channel.item.condition.text
|
||||||
|
|
||||||
|
if (!useFahrenheit) {
|
||||||
|
unit = "°" + unit;
|
||||||
|
}
|
||||||
|
|
||||||
|
script.setLabelText("weather stats",
|
||||||
|
"<table align=center width=90%>
|
||||||
|
<tr>
|
||||||
|
<td align=center>Weather in <b>" + city + "</b>: " + conditionText + " at <b>" + temp + " " + unit + "</b></tb>
|
||||||
|
</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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue