Skip to content

Examples

Davide Bassi edited this page Sep 11, 2023 · 5 revisions

Forecast

import com.openmeteo.api.common.Response
import com.openmeteo.api.common.time.Timezone
import com.openmeteo.api.common.units.TemperatureUnit

@OptIn(Response.ExperimentalGluedUnitTimeStepValues::class)
fun main() {
    val om = OpenMeteo("Trieste", "it")
    val forecast = om.forecast {
        daily = Forecast.Daily {
            listOf(temperature2mMin, temperature2mMax)
        }
        temperatureUnit = TemperatureUnit.Fahrenheit
        timezone = Timezone.auto
    }.getOrThrow()
    Forecast.Daily.run {
        forecast.daily.getValue(temperature2mMax).run {
            println("# $temperature2mMax ($unit)")
            values.forEach{ (t, v) -> println("> $t | $v") }
        }
    }
}
Clone this wiki locally