add kmi api, repo, and json #

This commit is contained in:
pranshulgg committed 2026-09-24 21:25:50 +05:30
1 parent 7ddeb9c271
commit a550ccee77
3 files changed
+156 -11

No files matched your search

@@ -1,22 +1,15 @@
package com.pranshulgg.weather_master_app.core.network.sources.weather.kmi
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.JmaApi
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.alerts.json.JmaWarningJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaAmedasCurrentJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaAmedasStationJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaAreaJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaForecastBlockJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaHourlyJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.jma.json.JmaWeekAreaEntryJson
import com.pranshulgg.weather_master_app.core.network.sources.weather.kmi.json.KmiWeatherJson
import okhttp3.OkHttpClient
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
import java.util.concurrent.TimeUnit
// Source - https://github.com/jdejaegh/irm-kmi-api
interface KmiApi {
@GET("appv4/?s=getForecasts")
@@ -24,7 +17,7 @@ interface KmiApi {
@Query("lat") lat: Double,
@Query("long") lon: Double,
@Query("k") key: String,
)
): Response<KmiWeatherJson>
companion object {
@@ -0,0 +1,80 @@
package com.pranshulgg.weather_master_app.core.network.sources.weather.kmi
import com.pranshulgg.weather_master_app.core.model.domain.location.Location
import com.pranshulgg.weather_master_app.core.model.domain.weather.Weather
import com.pranshulgg.weather_master_app.core.model.sources.Source
import com.pranshulgg.weather_master_app.core.model.weather.FinishedWeatherResult
import com.pranshulgg.weather_master_app.core.model.weather.WeatherDataPack
import com.pranshulgg.weather_master_app.core.network.sources.weather.mgm.MgmApi
import com.pranshulgg.weather_master_app.data.local.dao.alerts.AlertsDao
import com.pranshulgg.weather_master_app.data.local.dao.location.LocationKeysDao
import com.pranshulgg.weather_master_app.data.local.dao.weather.ApiKeysDao
import com.pranshulgg.weather_master_app.data.local.dao.weather.WeatherContextDao
import com.pranshulgg.weather_master_app.data.local.dao.weather.WeatherDao
import com.pranshulgg.weather_master_app.data.repository.capability.WeatherCapability
import com.pranshulgg.weather_master_app.data.repository.data.BaseRepository
import com.pranshulgg.weather_master_app.data.repository.weather.CacheModel
import java.security.MessageDigest
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Locale
import javax.inject.Inject
// Source - https://github.com/jdejaegh/irm-kmi-api
class KmiRepository @Inject constructor(
val dao: WeatherContextDao,
val weatherDao: WeatherDao,
val api: KmiApi,
val apiKeysDao: ApiKeysDao,
val locationKeysDao: LocationKeysDao,
val alertsDao: AlertsDao
) : BaseRepository() {
override val weatherSource = Source.KMI
override val alertSource = Source.KMI
override val airQualitySource = Source.NONE
override val providesAlerts = true
override fun weatherCapability(): WeatherCapability? {
return object : WeatherCapability {
override suspend fun fetchAndProcess(
location: Location,
isManualRefresh: Boolean,
isForceRefresh: Boolean,
cacheModel: CacheModel
): WeatherDataPack {
val response = api.fetchWeather(
lat = location.latitude,
lon = location.longitude,
key = generateIrmKmiKey()
)
}
override suspend fun saveToDb(data: WeatherDataPack, cacheModel: CacheModel) {
TODO("Not yet implemented")
}
override fun finishedResult(data: Weather): FinishedWeatherResult {
TODO("Not yet implemented")
}
}
}
}
private fun generateIrmKmiKey(): String {
val date = LocalDate.now().format(
DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.ROOT)
)
val input = "r9EnW374jkJ9acc;getForecasts;$date"
return MessageDigest
.getInstance("MD5")
.digest(input.toByteArray(Charsets.UTF_8))
.joinToString("") { "%02x".format(it) }
}
@@ -0,0 +1,72 @@
package com.pranshulgg.weather_master_app.core.network.sources.weather.kmi.json
import com.google.gson.annotations.SerializedName
data class KmiWeatherJson(
val obs: KmiCurrentWeatherJson,
@SerializedName("for") val forecast: KmiForecastJson
)
data class KmiCurrentWeatherJson(
val temp: Double?,
val ww: Double?,
)
data class KmiForecastJson(
val daily: List<KmiDayJson>,
val hourly: List<KmiHourJson>,
val warning: List<KmiWarningJson>
)
data class KmiDayJson(
val period: String?,
val tempMin: Double?,
val tempMax: Double?,
val ww1: Double?,
val ww2: Double?,
@SerializedName("ddText") val windDirectionText: KmiDayWindDirectionJson,
val wind: KmiDayWindJson,
val precipChance: Double?,
val precipQuantity: String?
)
data class KmiDayWindDirectionJson(
val en: String?
)
data class KmiDayWindJson(
val speed: Double?
)
data class KmiHourJson(
val hour: String?,
val temp: Double?,
val ww: Double?,
val precipChance: String?,
val precipQuantity: Double?,
val pressure: Double?,
val windSpeedKm: Double?,
val windDirectionText: KmiHourWindDirectionJson,
val dateShow: String?,
)
data class KmiHourWindDirectionJson(
val en: String?
)
data class KmiWarningJson(
val warningType: KmiWarningTypeJson,
val warningLevel: Double?,
val fromTimestamp: String?,
val toTimestamp: String?,
val text: KmiWarningTextJson
)
data class KmiWarningTypeJson(
val en: String?
)
data class KmiWarningTextJson(
val en: String?
)