SHOW:
|
|
- or go back to the newest paste.
| 1 | var http = require('http');
| |
| 2 | var zlib = require('zlib');
| |
| 3 | var Db = require('mongodb').Db,
| |
| 4 | Connection = require('mongodb').Connection,
| |
| 5 | Server = require('mongodb').Server,
| |
| 6 | BSON = require('mongodb').BSONNative;
| |
| 7 | ||
| 8 | var k = 1; | |
| 9 | // Put a friendly message on the terminal | |
| 10 | //console.log("cronJob started");
| |
| 11 | - | |
| 11 | + | |
| 12 | - | var db = new Db('xForum', new Server('localhost', Connection.DEFAULT_PORT, {forceServerObjectId: true}));
|
| 12 | + | |
| 13 | - | var request = http.get({
|
| 13 | + | |
| 14 | // Runs every weekday (Monday through Friday) | |
| 15 | // at 11:30:00 AM. It does not run on Saturday | |
| 16 | // or Sunday. | |
| 17 | - | headers: { 'accept-encoding': 'gzip' } });
|
| 17 | + | |
| 18 | ||
| 19 | var db = new Db('xForum', new Server('localhost', Connection.DEFAULT_PORT, {forceServerObjectId: true}));
| |
| 20 | ||
| 21 | ||
| 22 | ||
| 23 | ||
| 24 | var request = http.get({
| |
| 25 | host: 'www.earthempires.com', | |
| 26 | path: '/news_feed?apicode=edited_out_for_privacy', | |
| 27 | port: 80, | |
| 28 | headers: { 'accept-encoding': 'gzip' } }).on('error', function(){});
| |
| 29 | ||
| 30 | ||
| 31 | request.on('response', function(response) {
| |
| 32 | if (response.statusCode == 200){
| |
| 33 | switch (response.headers['content-encoding']) {
| |
| 34 | case 'gzip': | |
| 35 | var gunzip = zlib.createGunzip(); | |
| 36 | var data = ""; | |
| 37 | response.pipe(gunzip); | |
| 38 | gunzip.on('data', function(chunk) {
| |
| 39 | data += chunk; | |
| 40 | }); | |
| 41 | - | data.forEach(function(line) {
|
| 41 | + | |
| 42 | - | line = line.split(',');
|
| 42 | + | |
| 43 | if (err){
| |
| 44 | console.log("error:" + err);
| |
| 45 | process.exit(1); | |
| 46 | } | |
| 47 | - | |
| 47 | + | |
| 48 | - | var new_rank = {
|
| 48 | + | |
| 49 | - | serverid: line[0], |
| 49 | + | |
| 50 | - | resetid: line[1], |
| 50 | + | |
| 51 | - | newsid: line[2], |
| 51 | + | |
| 52 | - | timestamp: line[3]*1000, |
| 52 | + | |
| 53 | - | type: line[4], |
| 53 | + | data.forEach(function(line) {
|
| 54 | - | win: line[5], |
| 54 | + | line = line.split(',');
|
| 55 | - | attacker_num: line[6], |
| 55 | + | |
| 56 | - | attacker_name: line[7], |
| 56 | + | |
| 57 | - | defender_num: line[8], |
| 57 | + | |
| 58 | - | defender_name: line[9], |
| 58 | + | var new_rank = {
|
| 59 | - | result1: line[10], |
| 59 | + | serverid: line[0], |
| 60 | - | result2: line[11], |
| 60 | + | resetid: line[1], |
| 61 | - | a_tag: line[12], |
| 61 | + | newsid: line[2], |
| 62 | timestamp: line[3]*1000, | |
| 63 | - | killhit: line[14] |
| 63 | + | type: line[4], |
| 64 | win: line[5], | |
| 65 | attacker_num: line[6], | |
| 66 | attacker_name: line[7], | |
| 67 | - | }); |
| 67 | + | defender_num: line[8], |
| 68 | defender_name: line[9], | |
| 69 | result1: line[10], | |
| 70 | result2: line[11], | |
| 71 | a_tag: line[12], | |
| 72 | d_tag: line[13], | |
| 73 | killhit: line[14] | |
| 74 | }; | |
| 75 | collection.insert(new_rank); | |
| 76 | }); | |
| 77 | }); | |
| 78 | }); | |
| 79 | }); | |
| 80 | } | |
| 81 | } | |
| 82 | }); | |
| 83 | ||
| 84 | request.on('error', function(error){
| |
| 85 | console.log(error); | |
| 86 | console.log("hmph");
| |
| 87 | }); | |
| 88 | }, null, true); |