silvrgit/lib/today/swedishword.js
2016-03-31 17:12:25 +01:00

50 lines
1.2 KiB
JavaScript

/**
* 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 = {
getSwedishWord: function () {
return new Promise(function(resolve, reject) {
"use strict";
var t= new Date(), ms = t.getTime();
var 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();