Explorar o código

imperial/metric setting + additional data

Leonard Menzel %!s(int64=2) %!d(string=hai) anos
pai
achega
46c2d65f75

+ 3 - 3
client/src/components/Settings/WeatherSettings/WeatherSettings.tsx

@@ -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>

+ 6 - 4
utils/getExternalWeather.js

@@ -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,