silvrgit/lib/today/swedishword.js

39 lines
995 B
JavaScript
Raw Normal View History

2016-03-08 21:52:21 +00:00
/**
* Created by Martin on 15/02/2016.
*/
const http = require('http');
2017-03-22 15:48:36 +00:00
const request = require('request');
const util = require('util');
const logger = require('log4js').getLogger('swedish');
2017-03-22 15:48:36 +00:00
const to_json = require('xmljson').to_json;
2016-03-08 21:52:21 +00:00
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);
2016-03-31 16:12:25 +00:00
});
}, function(error, response, body) {
if(response.statusCode !== 200) {
logger.error(response.statusCode);
logger.error(body);
return reject(error);
}
});
});
}
2016-03-08 21:52:21 +00:00
};
// module.exports.getSwedishWord();