silvrgit/lib/today/swedishword.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-03-08 21:52:21 +00:00
/**
* Created by Martin on 15/02/2016.
*/
var http = require('http'), request = require('request'), util = require('util');
var jsonfile = require('jsonfile');
var log4js = require('log4js');
var logger = log4js.getLogger();
var to_json = require('xmljson').to_json;
require('sugar-date');
var file = __dirname + '/' + 'cal.json';
function saveData(v) {
jsonfile.writeFileSync(file, v);
}
module.exports = {
2016-03-31 16:12:25 +00:00
getSwedishWord: function () {
return new Promise(function(resolve, reject) {
"use strict";
2016-03-08 21:52:21 +00:00
var t= new Date(), ms = t.getTime();
2016-03-31 16:12:25 +00:00
var url = ['http://wotd.transparent.com/rss/swedish-widget.xml?t=', ms].join('');
2016-03-08 21:52:21 +00:00
logger.info(url);
request(url, function (err, resp, body) {
2016-03-31 16:12:25 +00:00
if (err) {
return reject(err);
}
2016-03-08 21:52:21 +00:00
to_json(body, function (error, data) {
2016-03-31 16:12:25 +00:00
return resolve(data);
2016-03-08 21:52:21 +00:00
});
2016-03-23 15:46:48 +00:00
}, function(error, response, body) {
if(response.statusCode !== 200) {
logger.error(response.statusCode);
logger.error(body);
2016-03-31 16:12:25 +00:00
return reject(error);
2016-03-23 15:46:48 +00:00
}
});
2016-03-08 21:52:21 +00:00
2016-03-31 16:12:25 +00:00
});
2016-03-08 21:52:21 +00:00
}
};
2016-03-23 15:46:48 +00:00
//module.exports.getSwedishWord();