Skip to content

Commit 784b8e0

Browse files
committed
feat(apix): daily sunset/sunrise time format
Use `TimeFormat` instead of `Unit`.
1 parent ada55c9 commit 784b8e0

3 files changed

Lines changed: 39 additions & 15 deletions

File tree

.github/scripts/options.sh

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ SerialName() {
3939

4040
# join the list values with serial names and enum names and prepare enum
4141
options() {
42-
values="$(list)"
43-
serialNames="$(echo "$values" | SerialName)"
44-
options="$(echo "$values" | CamelCase | suffix ',')"
42+
options="$(echo "$listed" | CamelCase | suffix ',')"
4543
cat <<END
4644
package $package.$endpoint
4745
@@ -58,9 +56,7 @@ END
5856
}
5957

6058
units() {
61-
values="$(list)"
62-
serialNames="$(echo "$values" | SerialName)"
63-
units="$(echo "$values" | camelCase | prefix "val " | suffix ': Unit? = null,')"
59+
units="$(echo "$listed" | camelCase | prefix "val " | suffix ': Unit? = null,')"
6460
cat <<END
6561
package $package.$endpoint
6662
@@ -79,6 +75,36 @@ END
7975
echo ") : Response${name^}.Units"
8076
}
8177

78+
values() {
79+
values="$(echo "$listed" | camelCase | prefix "val " | suffix ': Array<Float?>? = null,')"
80+
cat <<END
81+
package $package.$endpoint
82+
83+
import $package.common.response.Response${name^}
84+
import $package.common.time.TimeFormat
85+
import $package.common.units.Unit
86+
import kotlinx.serialization.SerialName
87+
import kotlinx.serialization.Serializable
88+
89+
@Serializable
90+
class ${name^}Units(
91+
override val time: TimeFormat,
92+
END
93+
paste -d $'\n' <(echo "$serialNames") <(echo "$units") \
94+
| prefix " "
95+
echo ") : Response${name^}.Units"
96+
}
97+
98+
group() {
99+
listed="$(list)"
100+
serialNames="$(echo "$listed" | SerialName)"
101+
options < "tmp/$endpoint.html" > "$endpoint/${name^}Options.kt"
102+
units < "tmp/$endpoint.html" > "$endpoint/${name^}Units.kt"
103+
if [ "$name" == "daily" ]; then
104+
sed -i -r 's/(sunrise|sunset): Unit/\1: TimeFormat/' "$endpoint/DailyUnits.kt"
105+
fi
106+
}
107+
82108
declare -A docs=(
83109
[airquality]="https://open-meteo.com/en/docs/air-quality-api"
84110
[ecmwf]="https://open-meteo.com/en/docs/ecmwf-api"
@@ -90,22 +116,20 @@ declare -A docs=(
90116
# should run in project root
91117
cd "lib/src/main/kotlin/$(echo "$package" | tr '.' '/')" || exit 1
92118

93-
# fetch only once html
119+
# fetch html only once
94120
mkdir tmp
95121
for endpoint in "${!docs[@]}"; do
96122
curl -s "${docs[$endpoint]}" > "tmp/$endpoint.html"
97123
done
98124

99125
name="hourly"
100126
for endpoint in airquality ecmwf forecast historical marine; do
101-
options < "tmp/$endpoint.html" > "$endpoint/HourlyOptions.kt"
102-
units < "tmp/$endpoint.html" > "$endpoint/HourlyUnits.kt"
127+
group < "tmp/$endpoint.html"
103128
done
104129

105130
name="daily"
106131
for endpoint in forecast historical marine; do
107-
options < "tmp/$endpoint.html" > "$endpoint/DailyOptions.kt"
108-
units < "tmp/$endpoint.html" > "$endpoint/DailyUnits.kt"
132+
group < "tmp/$endpoint.html"
109133
done
110134

111135
# delete html

lib/src/main/kotlin/com/openmeteo/apix/forecast/DailyUnits.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class DailyUnits(
2020
@SerialName("apparent_temperature_min")
2121
val apparentTemperatureMin: Unit? = null,
2222
@SerialName("sunrise")
23-
val sunrise: Unit? = null,
23+
val sunrise: TimeFormat? = null,
2424
@SerialName("sunset")
25-
val sunset: Unit? = null,
25+
val sunset: TimeFormat? = null,
2626
@SerialName("precipitation_sum")
2727
val precipitationSum: Unit? = null,
2828
@SerialName("rain_sum")

lib/src/main/kotlin/com/openmeteo/apix/historical/DailyUnits.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class DailyUnits(
1818
@SerialName("apparent_temperature_min")
1919
val apparentTemperatureMin: Unit? = null,
2020
@SerialName("sunrise")
21-
val sunrise: Unit? = null,
21+
val sunrise: TimeFormat? = null,
2222
@SerialName("sunset")
23-
val sunset: Unit? = null,
23+
val sunset: TimeFormat? = null,
2424
@SerialName("shortwave_radiation_sum")
2525
val shortwaveRadiationSum: Unit? = null,
2626
@SerialName("precipitation_sum")

0 commit comments

Comments
 (0)