Merge 46c2d65f75
into 3c347c854c
This commit is contained in:
commit
f74c4244be
4 changed files with 277 additions and 566 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>
|
||||
|
|
|
@ -13,345 +13,10 @@ export enum TimeOfDay {
|
|||
night
|
||||
}
|
||||
|
||||
const mapFromJson = require('./WeatherMapping.json')
|
||||
|
||||
export class IconMapping {
|
||||
private conditions: WeatherCondition[] = [
|
||||
{
|
||||
code: 1000,
|
||||
icon: {
|
||||
day: 'clear-day',
|
||||
night: 'clear-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1003,
|
||||
icon: {
|
||||
day: 'partly-cloudy-day',
|
||||
night: 'partly-cloudy-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1006,
|
||||
icon: {
|
||||
day: 'cloudy',
|
||||
night: 'cloudy'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1009,
|
||||
icon: {
|
||||
day: 'cloudy',
|
||||
night: 'cloudy'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1030,
|
||||
icon: {
|
||||
day: 'fog',
|
||||
night: 'fog'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1063,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1066,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1069,
|
||||
icon: {
|
||||
day: 'rain-snow-day',
|
||||
night: 'rain-snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1072,
|
||||
icon: {
|
||||
day: 'sleet',
|
||||
night: 'sleet'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1087,
|
||||
icon: {
|
||||
day: 'thunder-day',
|
||||
night: 'thunder-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1114,
|
||||
icon: {
|
||||
day: 'snow',
|
||||
night: 'snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1117,
|
||||
icon: {
|
||||
day: 'snow',
|
||||
night: 'snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1135,
|
||||
icon: {
|
||||
day: 'fog',
|
||||
night: 'fog'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1147,
|
||||
icon: {
|
||||
day: 'fog',
|
||||
night: 'fog'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1150,
|
||||
icon: {
|
||||
day: 'rain',
|
||||
night: 'rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1153,
|
||||
icon: {
|
||||
day: 'rain',
|
||||
night: 'rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1168,
|
||||
icon: {
|
||||
day: 'sleet',
|
||||
night: 'sleet'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1171,
|
||||
icon: {
|
||||
day: 'sleet',
|
||||
night: 'sleet'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1180,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1183,
|
||||
icon: {
|
||||
day: 'rain',
|
||||
night: 'rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1186,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1189,
|
||||
icon: {
|
||||
day: 'rain',
|
||||
night: 'rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1192,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1195,
|
||||
icon: {
|
||||
day: 'rain',
|
||||
night: 'rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1198,
|
||||
icon: {
|
||||
day: 'sleet',
|
||||
night: 'sleet'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1201,
|
||||
icon: {
|
||||
day: 'sleet',
|
||||
night: 'sleet'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1204,
|
||||
icon: {
|
||||
day: 'rain-snow',
|
||||
night: 'rain-snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1207,
|
||||
icon: {
|
||||
day: 'rain-snow',
|
||||
night: 'rain-snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1210,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1213,
|
||||
icon: {
|
||||
day: 'snow',
|
||||
night: 'snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1216,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1219,
|
||||
icon: {
|
||||
day: 'snow',
|
||||
night: 'snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1222,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1225,
|
||||
icon: {
|
||||
day: 'snow',
|
||||
night: 'snow'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1237,
|
||||
icon: {
|
||||
day: 'hail',
|
||||
night: 'hail'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1240,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1243,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1246,
|
||||
icon: {
|
||||
day: 'rain-day',
|
||||
night: 'rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1249,
|
||||
icon: {
|
||||
day: 'rain-snow-day',
|
||||
night: 'rain-snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1252,
|
||||
icon: {
|
||||
day: 'rain-snow-day',
|
||||
night: 'rain-snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1255,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1258,
|
||||
icon: {
|
||||
day: 'snow-day',
|
||||
night: 'snow-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1261,
|
||||
icon: {
|
||||
day: 'hail',
|
||||
night: 'hail'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1264,
|
||||
icon: {
|
||||
day: 'hail',
|
||||
night: 'hail'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1273,
|
||||
icon: {
|
||||
day: 'thunder-rain-day',
|
||||
night: 'thunder-rain-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1276,
|
||||
icon: {
|
||||
day: 'thunder-rain',
|
||||
night: 'thunder-rain'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1279,
|
||||
icon: {
|
||||
day: 'thunder-day',
|
||||
night: 'thunder-night'
|
||||
}
|
||||
},
|
||||
{
|
||||
code: 1282,
|
||||
icon: {
|
||||
day: 'thunder',
|
||||
night: 'thunder'
|
||||
}
|
||||
}
|
||||
];
|
||||
private conditions: WeatherCondition[] = mapFromJson.mapping
|
||||
|
||||
mapIcon(weatherStatusCode: number, timeOfDay: TimeOfDay): IconKey {
|
||||
const mapping = this.conditions.find((condition: WeatherCondition) => condition.code === weatherStatusCode);
|
||||
|
|
|
@ -1,340 +1,382 @@
|
|||
{
|
||||
"mapping": [
|
||||
{
|
||||
"code": 1000,
|
||||
"code": 800,
|
||||
"icon": {
|
||||
"day": "clear-day",
|
||||
"night": "clear-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1003,
|
||||
"code": 801,
|
||||
"icon": {
|
||||
"day": "partly-cloudy-day",
|
||||
"night": "partly-cloudy-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1006,
|
||||
"code": 802,
|
||||
"icon": {
|
||||
"day": "partly-cloudy-day",
|
||||
"night": "partly-cloudy-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 803,
|
||||
"icon": {
|
||||
"day": "cloudy",
|
||||
"night": "cloudy"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1009,
|
||||
"code": 804,
|
||||
"icon": {
|
||||
"day": "cloudy",
|
||||
"night": "cloudy"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1030,
|
||||
"code": 701,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1063,
|
||||
"code": 711,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1066,
|
||||
"code": 721,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 731,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 741,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 751,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 761,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 771,
|
||||
"icon": {
|
||||
"day": "wind",
|
||||
"night": "wind"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 781,
|
||||
"icon": {
|
||||
"day": "wind",
|
||||
"night": "wind"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 600,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1069,
|
||||
"code": 601,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 602,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 611,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 612,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 613,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 615,
|
||||
"icon": {
|
||||
"day": "rain-snow-day",
|
||||
"night": "rain-snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1072,
|
||||
"code": 616,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
"day": "rain-snow-day",
|
||||
"night": "rain-snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1087,
|
||||
"icon": {
|
||||
"day": "thunder-day",
|
||||
"night": "thunder-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1114,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1117,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1135,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1147,
|
||||
"icon": {
|
||||
"day": "fog",
|
||||
"night": "fog"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1150,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1153,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1168,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1171,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1180,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1183,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1186,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1189,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1192,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1195,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1198,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1201,
|
||||
"icon": {
|
||||
"day": "sleet",
|
||||
"night": "sleet"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1204,
|
||||
"code": 620,
|
||||
"icon": {
|
||||
"day": "rain-snow",
|
||||
"night": "rain-snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1207,
|
||||
"code": 621,
|
||||
"icon": {
|
||||
"day": "rain-snow",
|
||||
"night": "rain-snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1210,
|
||||
"code": 622,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
"day": "rain-snow",
|
||||
"night": "rain-snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1213,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1216,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1219,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1222,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1225,
|
||||
"icon": {
|
||||
"day": "snow",
|
||||
"night": "snow"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1237,
|
||||
"icon": {
|
||||
"day": "hail",
|
||||
"night": "hail"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1240,
|
||||
"code": 500,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1243,
|
||||
"code": 501,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1246,
|
||||
"code": 502,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1249,
|
||||
"code": 503,
|
||||
"icon": {
|
||||
"day": "rain-snow-day",
|
||||
"night": "rain-snow-night"
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1252,
|
||||
"code": 504,
|
||||
"icon": {
|
||||
"day": "rain-snow-day",
|
||||
"night": "rain-snow-night"
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1255,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1258,
|
||||
"icon": {
|
||||
"day": "snow-day",
|
||||
"night": "snow-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1261,
|
||||
"code": 511,
|
||||
"icon": {
|
||||
"day": "hail",
|
||||
"night": "hail"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1264,
|
||||
"code": 520,
|
||||
"icon": {
|
||||
"day": "hail",
|
||||
"night": "hail"
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1273,
|
||||
"code": 521,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 522,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 531,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 300,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 301,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 302,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 310,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 311,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 312,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 313,
|
||||
"icon": {
|
||||
"day": "rain-day",
|
||||
"night": "rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 314,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 321,
|
||||
"icon": {
|
||||
"day": "rain",
|
||||
"night": "rain"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 200,
|
||||
"icon": {
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1276,
|
||||
"code": 201,
|
||||
"icon": {
|
||||
"day": "thunder-rain",
|
||||
"night": "thunder-rain"
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1279,
|
||||
"code": 202,
|
||||
"icon": {
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 210,
|
||||
"icon": {
|
||||
"day": "thunder-day",
|
||||
"night": "thunder-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 1282,
|
||||
"code": 211,
|
||||
"icon": {
|
||||
"day": "thunder-day",
|
||||
"night": "thunder-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 212,
|
||||
"icon": {
|
||||
"day": "thunder",
|
||||
"night": "thunder"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 221,
|
||||
"icon": {
|
||||
"day": "thunder-day",
|
||||
"night": "thunder-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 230,
|
||||
"icon": {
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 231,
|
||||
"icon": {
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
},
|
||||
{
|
||||
"code": 232,
|
||||
"icon": {
|
||||
"day": "thunder-rain-day",
|
||||
"night": "thunder-rain-night"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -3,27 +3,31 @@ 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(
|
||||
`http://api.weatherapi.com/v1/current.json?key=${secret}&q=${lat},${long}`
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${long}&appid=${secret}&units=${units}`
|
||||
);
|
||||
|
||||
// Save weather data
|
||||
const cursor = res.data.current;
|
||||
const cursor = res.data;
|
||||
const isDay = (Math.floor(Date.now()/1000) < cursor.sys.sunset) | 0
|
||||
const weatherData = await Weather.create({
|
||||
externalLastUpdate: cursor.last_updated,
|
||||
tempC: cursor.temp_c,
|
||||
tempF: cursor.temp_f,
|
||||
isDay: cursor.is_day,
|
||||
cloud: cursor.cloud,
|
||||
conditionText: cursor.condition.text,
|
||||
conditionCode: cursor.condition.code,
|
||||
humidity: cursor.humidity,
|
||||
windK: cursor.wind_kph,
|
||||
windM: cursor.wind_mph,
|
||||
externalLastUpdate: cursor.dt,
|
||||
tempC: cursor.main.temp,
|
||||
tempF: cursor.main.temp,
|
||||
isDay: isDay,
|
||||
cloud: cursor.clouds.all,
|
||||
conditionText: cursor.weather[0].main,
|
||||
conditionCode: cursor.weather[0].id,
|
||||
humidity: cursor.main.humidity,
|
||||
windK: cursor.wind.speed,
|
||||
windM: 0,
|
||||
});
|
||||
return weatherData;
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Reference in a new issue