summaryrefslogtreecommitdiff
path: root/services/Weather.qml
blob: 13503f95ba0743c4465e5b52f915b2533c6bab85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pragma Singleton

import "root:/utils"
import Quickshell
import Quickshell.Io

Singleton {
    id: root

    property string icon
    property string description
    property real temperature

    function reload(): void {
        wttrProc.running = true;
    }

    Process {
        id: wttrProc

        running: true
        command: ["fish", "-c", `curl "https://wttr.in/$(curl ipinfo.io | jq -r '.city' | string replace -a ' ' '%20')?format=j1" | jq -c '.current_condition[0] | {code: .weatherCode, desc: .weatherDesc[0].value, temp: .temp_C}'`]
        stdout: SplitParser {
            onRead: data => {
                const json = JSON.parse(data);
                root.icon = Icons.getWeatherIcon(json.code);
                root.description = json.desc;
                root.temperature = parseFloat(json.temp);
            }
        }
    }
}