yr-lib
Advanced tools
Comparing version 1.0.13 to 1.0.14
57
index.js
@@ -24,4 +24,3 @@ var fs = require('fs'), | ||
if (!error && response.statusCode == 200) { | ||
fs.writeFile(__dirname + '/foo.xml', body, 'utf8'); | ||
xmlParsing(local_time, function(data) { | ||
xmlParsing(body, local_time, function(data) { | ||
callback(data); | ||
@@ -37,41 +36,31 @@ }); | ||
function xmlParsing(local_time, callback) { | ||
function xmlParsing(xml_data, local_time, callback) { | ||
var filterdData | ||
fs.readFile(__dirname + '/foo.xml', function(err, data) { | ||
var jsonData = parser.toJson(data); | ||
var jsonData = parser.toJson(xml_data); | ||
fs.writeFile(__dirname + '/weatherjson.json', jsonData); | ||
fs.readFile(__dirname + '/weatherjson.json', 'utf8', function(err, data) { | ||
if(!err) { | ||
var parsedData; | ||
try { | ||
parsedData = JSON.parse(data); | ||
} catch(err) { | ||
callback({"Error": "unable to parse the json weather file"}); | ||
} | ||
var parsedData; | ||
try { | ||
parsedData = JSON.parse(jsonData); | ||
if(local_time != null) { | ||
var time = moment(local_time).utc().add(1, 'h').startOf('hour').format(); | ||
time = time.substring(0, 13); | ||
if(local_time != null) { | ||
var time = moment(local_time).utc().add(1, 'h').startOf('hour').format(); | ||
time = time.substring(0, 13); | ||
filterdData = _.remove(parsedData.weatherdata.product.time, function(n) { | ||
return n.from.substring(0,13) && n.to.substring(0,13) === time; | ||
}); | ||
callback(filterdData); | ||
} else { | ||
callback(parsedData.weatherdata.product.time); | ||
} | ||
filterdData = _.remove(parsedData.weatherdata.product.time, function(n) { | ||
return n.from.substring(0,13) && n.to.substring(0,13) === time; | ||
} else { | ||
callback({"Error": "unable to read the weather json file"}); | ||
} | ||
}) | ||
}); | ||
callback(filterdData); | ||
}); | ||
} else { | ||
callback(parsedData.weatherdata.product.time); | ||
} | ||
} catch(err) { | ||
callback({"Error": "unable to parse the json weather data"}); | ||
} | ||
} |
{ | ||
"name": "yr-lib", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "yr.no api", | ||
@@ -20,5 +20,4 @@ "main": "index.js", | ||
"moment": "^2.15.1", | ||
"request": "^2.75.0", | ||
"xml2json": "^0.10.0" | ||
"request": "^2.75.0" | ||
} | ||
} |
3
2943
47
- Removedxml2json@^0.10.0
- Removedbindings@1.5.0(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedhoek@4.3.1(transitive)
- Removedisemail@2.2.1(transitive)
- Removeditems@2.2.1(transitive)
- Removedjoi@9.2.0(transitive)
- Removednan@2.19.0(transitive)
- Removednode-expat@2.4.1(transitive)
- Removedtopo@2.1.1(transitive)
- Removedxml2json@0.10.0(transitive)