silvrgit/lib/today/swedishword.js
2017-10-13 10:39:58 +01:00

39 lines
995 B
JavaScript

/**
* Created by Martin on 15/02/2016.
*/
const http = require('http');
const request = require('request');
const util = require('util');
const logger = require('log4js').getLogger('swedish');
const to_json = require('xmljson').to_json;
require('sugar-date');
module.exports = {
'getSwedishWord': function () {
return new Promise(function(resolve, reject) {
const t = new Date(), ms = t.getTime();
const url = ['http://wotd.transparent.com/rss/swedish-widget.xml?t=', ms].join('');
// logger.info(url);
request(url, function (err, resp, body) {
if (err)
return reject(err);
to_json(body, function (error, data) {
return resolve(data);
});
}, function(error, response, body) {
if(response.statusCode !== 200) {
logger.error(response.statusCode);
logger.error(body);
return reject(error);
}
});
});
}
};
// module.exports.getSwedishWord();