11function parseWeather ( response ) {
22 let owmData = JSON . parse ( response ) ;
33
4- let isOwmData = false ;
5- try {
6- isOwmData = ( owmData . lat && owmData . lon ) && owmData . current . weather && owmData . current ;
7- } catch ( _e ) { }
4+ let isOwmData = owmData . coord && owmData . weather && owmData . main ;
85
96 if ( isOwmData ) {
107 let json = require ( "Storage" ) . readJSON ( 'weather.json' ) || { } ;
118 let weather = { } ;
129 weather . time = Date . now ( ) ;
13- weather . hum = owmData . current . humidity ;
14- weather . temp = owmData . current . temp ;
15- weather . code = owmData . current . weather [ 0 ] . id ;
16- weather . wdir = owmData . current . wind_deg ;
17- weather . wind = owmData . current . wind_speed ;
18- weather . loc = owmData . name || "" ;
19- weather . txt = owmData . current . weather [ 0 ] . main ;
20- weather . hpa = owmData . current . pressure || 0 ;
10+ weather . hum = owmData . main . humidity ;
11+ weather . temp = owmData . main . temp ;
12+ weather . code = owmData . weather [ 0 ] . id ;
13+ weather . wdir = owmData . wind . deg ;
14+ weather . wind = owmData . wind . speed ;
15+ weather . loc = owmData . name ;
16+ weather . txt = owmData . weather [ 0 ] . main ;
17+ weather . hpa = owmData . main . pressure || 0 ;
2118
2219 if ( weather . wdir != null ) {
2320 let deg = weather . wdir ;
@@ -43,7 +40,7 @@ exports.pull = function(completionCallback) {
4340 "location" : "London"
4441 } ;
4542 let settings = require ( "Storage" ) . readJSON ( "owmweather.json" , 1 ) ;
46- let uri = "https://api.openweathermap.org/data/3.0/onecall ?lat=" + location . lat . toFixed ( 2 ) + "&lon=" + location . lon . toFixed ( 2 ) + "&exclude=minutely, hourly,daily,alerts &appid=" + settings . apikey ;
43+ let uri = "https://api.openweathermap.org/data/2.5/weather ?lat=" + location . lat . toFixed ( 2 ) + "&lon=" + location . lon . toFixed ( 2 ) + "&exclude=hourly,daily&appid=" + settings . apikey ;
4744 if ( Bangle . http ) {
4845 Bangle . http ( uri , { timeout :10000 } ) . then ( event => {
4946 let result = parseWeather ( event . resp ) ;
0 commit comments