silvrgit/lib/today/swedishword.js
2017-03-22 15:48:36 +00:00

42 lines
1.1 KiB
JavaScript

/**
* Created by Martin on 15/02/2016.
*/
let http = require('http');
const request = require('request');
let util = require('util');
const logger = require('log4js').getLogger();
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();