Skip to content

Commit

Permalink
Updated weather API
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme committed Jun 23, 2024
1 parent fc90de4 commit a0b7f53
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
10 changes: 5 additions & 5 deletions client/src/Forecast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
</tr>
<tr>
<td>Max.:</td>
<td>{fdata.tmax} C</td>
<td>{fdata.max_temp} C</td>
</tr>
<tr>
<td>Min.:</td>
<td>{fdata.tmin} C</td>
<td>{fdata.min_tem} C</td>
</tr>
<tr>
<td>Zon:</td>
<td>{fdata.zon} %</td>
<td>{fdata.zond_perc_dag} %</td>
</tr>
<tr>
<td>Neerslag:</td>
<td>{fdata.neerslag} %</td>
<td>{fdata.neersl_perc_dag} %</td>
</tr>
<tr>
<td>Wind:</td>
<td>{fdata.windk} Bft</td>
<td>{fdata.windbft} Bft</td>
</tr>
<tr>
<td>Richting:</td>
Expand Down
34 changes: 16 additions & 18 deletions lib/getWeatherInfo.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
export async function getWeatherInfo(location, key) {
const url = `http://weerlive.nl/api/json-data-10min.php?key=${key}&locatie=${location}`;
try {
const response = await fetch(url);
const json = await response.json();
const today = json.liveweer[0];
return {
date: Number(new Date()),
weer: today.d0weer,
tmax: Number(today.d0tmax),
tmin: Number(today.d0tmin),
windk: Number(today.d0windk),
windr: today.d0windr,
neerslag: Number(today.d0neerslag),
zon: Number(today.d0zon),
};
} catch (error) {
throw new Error("error parsing weather data");
}
const url =
`https://weerlive.nl/api/weerlive_api_v2.php?key=${key}&locatie=${location}`;

const response = await fetch(url);
const json = await response.json();
const today = json.wk_verw[0];
return {
date: today.dag,
weer: today.image,
max_temp: Number(today.max_temp),
min_tem: Number(today.min_temp),
windbft: Number(today.windbft),
windr: today.windr,
neersl_perc_dag: Number(today.neersl_perc_dag),
zond_perc_dag: Number(today.zond_perc_dag),
};
}
2 changes: 1 addition & 1 deletion rules/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isSunnyForecast(minTemp) {
debug("forecast says not sunny");
return false;
}
if (minTemp && forecast.tmax <= minTemp) {
if (minTemp && forecast.max_temp <= minTemp) {
debug("forecast says sunny but not warm enough");
return false;
}
Expand Down

0 comments on commit a0b7f53

Please sign in to comment.