Das Tool auf ein Objektbasiertes Schema umgestellt, damit ich auch Events benutzen kann.
This commit is contained in:
parent
f0ba7e05a8
commit
58bea13ce8
2 changed files with 94 additions and 43 deletions
82
event.js
Normal file
82
event.js
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
* "THE VODKA-WARE LICENSE" (Revision 42):
|
||||||
|
* <tim@bandenkrieg.hacked.jp> wrote this file. As long as you retain this notice you
|
||||||
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
* this stuff is worth it, you can buy me a vodka in return. Tim Schumacher
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
var
|
||||||
|
events = require('events')
|
||||||
|
,util = require('util')
|
||||||
|
,dgram = require('dgram')
|
||||||
|
,config = require('./config')
|
||||||
|
,http = require('https')
|
||||||
|
,jsdom = require('jsdom')
|
||||||
|
,log = require('sys').log;
|
||||||
|
|
||||||
|
|
||||||
|
function EventTool() {
|
||||||
|
events.EventEmitter.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
EventTool.super_ = events.EventEmitter;
|
||||||
|
EventTool.prototype = Object.create(events.EventEmitter.prototype, {
|
||||||
|
constructor: {
|
||||||
|
value: EventTool,
|
||||||
|
enumerable: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
EventTool.prototype.config = require('./config');
|
||||||
|
EventTool.prototype.RequestData = '';
|
||||||
|
EventTool.prototype.events = [];
|
||||||
|
|
||||||
|
EventTool.prototype.parseData = function() {
|
||||||
|
var self = this.req.EventTool;
|
||||||
|
jsdom.env(
|
||||||
|
self.RequestData,
|
||||||
|
["http://code.jquery.com/jquery.js"],
|
||||||
|
function (errors, window) {
|
||||||
|
var wiki_text = window.$("#wiki__text").val();
|
||||||
|
var re = /\s\* (\d{4})\-(\d{2})\-(\d{2}) (\d{2})\:(\d{2}) - (\d{2})\:(\d{2}) (.*)/g;
|
||||||
|
var match = null;
|
||||||
|
var events = [];
|
||||||
|
while (match = re.exec(wiki_text)) {
|
||||||
|
var event = {
|
||||||
|
startdate : new Date(match[1], match[2], match[3], match[4], match[5])
|
||||||
|
,enddate : new Date(match[1], match[2], match[3], match[6], match[7])
|
||||||
|
,text : match[8]
|
||||||
|
};
|
||||||
|
events.push(event);
|
||||||
|
}
|
||||||
|
console.log(events);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTool.prototype.processResponse = function(res) {
|
||||||
|
var self = this.EventTool;
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
res.on('data', function(d) {
|
||||||
|
self.RequestData = self.RequestData + d;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end',self.parseData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EventTool.prototype.run = function() {
|
||||||
|
var req = http.request(this.config.url,this.processResponse);
|
||||||
|
req.EventTool = this;
|
||||||
|
|
||||||
|
req.end();
|
||||||
|
|
||||||
|
req.on('error', function(e) {
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.EventTool = EventTool;
|
55
termine.js
55
termine.js
|
@ -1,46 +1,15 @@
|
||||||
var config = require('./config');
|
/*
|
||||||
var http = require('https');
|
* ----------------------------------------------------------------------------
|
||||||
var jsdom = require('jsdom');
|
* "THE VODKA-WARE LICENSE" (Revision 42):
|
||||||
|
* <tim@bandenkrieg.hacked.jp> wrote this file. As long as you retain this notice you
|
||||||
|
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||||
|
* this stuff is worth it, you can buy me a vodka in return. Tim Schumacher
|
||||||
|
* ----------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
var EventTool = require('./event').EventTool;
|
||||||
|
|
||||||
|
|
||||||
var data = '';
|
var et = new EventTool();
|
||||||
|
|
||||||
function parseData() {
|
et.run();
|
||||||
jsdom.env(
|
|
||||||
data,
|
|
||||||
["http://code.jquery.com/jquery.js"],
|
|
||||||
function (errors, window) {
|
|
||||||
var wiki_text = window.$("#wiki__text").val();
|
|
||||||
var re = /\s\* (\d{4})\-(\d{2})\-(\d{2}) (\d{2})\:(\d{2}) - (\d{2})\:(\d{2}) (.*)/g;
|
|
||||||
var match = null;
|
|
||||||
var events = [];
|
|
||||||
while (match = re.exec(wiki_text)) {
|
|
||||||
var event = {
|
|
||||||
startdate : new Date(match[1], match[2], match[3], match[4], match[5])
|
|
||||||
,enddate : new Date(match[1], match[2], match[3], match[6], match[7])
|
|
||||||
,text : match[8]
|
|
||||||
};
|
|
||||||
events.push(event);
|
|
||||||
}
|
|
||||||
console.log(events);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function processResponse(res) {
|
|
||||||
if (res.statusCode == 200) {
|
|
||||||
res.on('data', function(d) {
|
|
||||||
data = data + d;
|
|
||||||
});
|
|
||||||
|
|
||||||
res.on('end',parseData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var req = http.request(config.url,processResponse);
|
|
||||||
|
|
||||||
req.end();
|
|
||||||
|
|
||||||
req.on('error', function(e) {
|
|
||||||
console.error(e);
|
|
||||||
});
|
|
||||||
|
|
Reference in a new issue