imperial/metric setting + additional data
This commit is contained in:
parent
b23d17f43b
commit
46c2d65f75
2 changed files with 9 additions and 7 deletions
|
@ -110,10 +110,10 @@ export const WeatherSettings = (): JSX.Element => {
|
|||
onChange={(e) => inputChangeHandler(e)}
|
||||
/>
|
||||
<span>
|
||||
Using
|
||||
<a href="https://www.weatherapi.com/pricing.aspx" target="blank">
|
||||
Now using
|
||||
<a href="https://openweathermap.org/api" target="blank">
|
||||
{' '}
|
||||
Weather API
|
||||
OpenWeatherMap
|
||||
</a>
|
||||
. Key is required for weather module to work.
|
||||
</span>
|
||||
|
|
|
@ -3,13 +3,15 @@ const axios = require('axios');
|
|||
const loadConfig = require('./loadConfig');
|
||||
|
||||
const getExternalWeather = async () => {
|
||||
const { WEATHER_API_KEY: secret, lat, long } = await loadConfig();
|
||||
|
||||
const { WEATHER_API_KEY: secret, lat, long, isCelsius } = await loadConfig();
|
||||
|
||||
//units = standard, metric, imperial
|
||||
const units = isCelsius?'metric':'imperial'
|
||||
|
||||
// Fetch data from external API
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=${secret}&units=metric`
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=${secret}&units=${units}`
|
||||
);
|
||||
|
||||
// Save weather data
|
||||
|
@ -18,7 +20,7 @@ const getExternalWeather = async () => {
|
|||
const weatherData = await Weather.create({
|
||||
externalLastUpdate: cursor.dt,
|
||||
tempC: cursor.main.temp,
|
||||
tempF: 0,
|
||||
tempF: cursor.main.temp,
|
||||
isDay: isDay,
|
||||
cloud: cursor.clouds.all,
|
||||
conditionText: cursor.weather[0].main,
|
||||
|
|
Loading…
Add table
Reference in a new issue