silvrgit/lib/today/swedishword.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-03-08 21:52:21 +00:00
/**
* Created by Martin on 15/02/2016.
*/
2017-03-22 15:48:36 +00:00
let http = require('http');
const request = require('request');
let util = require('util');
const logger = require('log4js').getLogger();
const to_json = require('xmljson').to_json;
2016-03-08 21:52:21 +00:00
require('sugar-date');
module.exports = {
2016-03-31 16:12:25 +00:00
getSwedishWord: function () {
return new Promise(function(resolve, reject) {
2016-03-08 21:52:21 +00:00
2017-03-22 15:48:36 +00:00
const t = new Date(), ms = t.getTime();
2016-03-08 21:52:21 +00:00
2017-03-22 15:48:36 +00:00
const url = ['http://wotd.transparent.com/rss/swedish-widget.xml?t=', ms].join('');
// logger.info(url);
2016-03-08 21:52:21 +00:00
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();