mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 11:39:36 +02:00
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)}
|
onChange={(e) => inputChangeHandler(e)}
|
||||||
/>
|
/>
|
||||||
<span>
|
<span>
|
||||||
Using
|
Now using
|
||||||
<a href="https://www.weatherapi.com/pricing.aspx" target="blank">
|
<a href="https://openweathermap.org/api" target="blank">
|
||||||
{' '}
|
{' '}
|
||||||
Weather API
|
OpenWeatherMap
|
||||||
</a>
|
</a>
|
||||||
. Key is required for weather module to work.
|
. Key is required for weather module to work.
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -3,13 +3,15 @@ const axios = require('axios');
|
||||||
const loadConfig = require('./loadConfig');
|
const loadConfig = require('./loadConfig');
|
||||||
|
|
||||||
const getExternalWeather = async () => {
|
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
|
//units = standard, metric, imperial
|
||||||
|
const units = isCelsius?'metric':'imperial'
|
||||||
|
|
||||||
// Fetch data from external API
|
// Fetch data from external API
|
||||||
try {
|
try {
|
||||||
const res = await axios.get(
|
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
|
// Save weather data
|
||||||
|
@ -18,7 +20,7 @@ const getExternalWeather = async () => {
|
||||||
const weatherData = await Weather.create({
|
const weatherData = await Weather.create({
|
||||||
externalLastUpdate: cursor.dt,
|
externalLastUpdate: cursor.dt,
|
||||||
tempC: cursor.main.temp,
|
tempC: cursor.main.temp,
|
||||||
tempF: 0,
|
tempF: cursor.main.temp,
|
||||||
isDay: isDay,
|
isDay: isDay,
|
||||||
cloud: cursor.clouds.all,
|
cloud: cursor.clouds.all,
|
||||||
conditionText: cursor.weather[0].main,
|
conditionText: cursor.weather[0].main,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue