// var express = require('express');
// var app = express();
var sX = require('scrapper-x');
var request = require('request');
var tonicExpress = require("https://runkit.com/ego/endpoint")//("tonic/endpoint/");
var app = tonicExpress(module.exports)
// app.get('/',function( req, res){
// console.log('done scraping');
var option1 = {
repeatItemGroup: 'tr.match ',
dataFormat: {
date: {
selector: 'td.date',
type: 'text'
},
home: {
selector: '.team.team-a > a',
type: 'text'
},
away: {
selector: '.team-b',
type: 'text'
},
goals: {
selector: '.score',
type: 'text'
}
}
};
/* GET home page. */
app.get('/match', function(req, res, next) {
request('http://int.soccerway.com/national/myanmar/national-league/2016/regular-season/r33992/matches/',
function(error, response, body) {
var scrappedResult = {};
if (!error && response.statusCode == 200) {
scrappedResult = sX.scrape(body, option1);
}
// scrappedResult.push({
// "date" : date,
// "home" : home,
// "away" : away,
// "goals" : goals
// });
scrappedResult.push({date:'', home: ''})
res.status(200).json(scrappedResult);
});
});
var option2 = {
repeatItemGroup: 'tr.team_rank',
dataFormat: {
rank: {
selector: '.rank',
type: 'text'
},
team: {
selector: '.text.team.large-link > a',
type: 'text'
},
played: {
selector: '.number.total.mp',
type: 'text'
},
wins: {
selector: '.number.total.won.total_won',
type: 'text'
},
loses: {
selector: '.number.lost',
type: 'text'
},
draws: {
selector: '.number.drawn',
type: 'text'
},
gd: {
selector: 'td.number.gd',
type: 'text'
},
ga: {
selector: 'td.number.total.ga',
type: 'text'
},
goaltotal: {
selector: 'td.number.total.gf',
type: 'text'
},
point: {
selector: '.number.points',
type: 'text'
}
}
};
/* GET home page. */
app.get('/standing', function(req, res, next) {
request('http://int.soccerway.com/national/myanmar/national-league/2016/regular-season/r33992/tables/',
function(error, response, body) {
var ranking = {};
if (!error && response.statusCode == 200) {
rankingResult = sX.scrape(body, option2);
}
// scrappedResult.push({
// "date" : date,
// "home" : home,
// "away" : away,
// "goals" : goals
// });
// scrappedResult.push({date:'', home: ''})
res.status(200).json(rankingResult);
console.log(rankingResult);
});
});
exports.endpoint = function(request, response) {
response.end(standing);
}
var port = process.env.PORT || 3000;
// app.listen('3000')
// console.log('Magic happens on port 8081');
// exports = module.exports = app;
app.listen(3000)
console.log('The party is on at port ' + port);
exports = module.exports = app;