-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
185 lines (162 loc) · 7.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const express = require('express');
const cheerio = require('cheerio');
const randomUseragent = require('random-useragent');
const axios = require('axios');
const rua = randomUseragent.getRandom();
const app = express();
const matchdata = require('./app.json');
app.get('/', function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET');
res.header('X-Frame-Options', 'DENY');
res.header('X-XSS-Protection', '1; mode=block');
res.header('X-Content-Type-Options', 'nosniff');
res.header('Strict-Transport-Security', 'max-age=63072000');
res.setHeader('Content-Type', 'application/json');
app.disable('x-powered-by');
res.json('Live Cricket score API - v0.0.1');
});
app.get('/live', function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET');
res.header('X-Frame-Options', 'DENY');
res.header('X-XSS-Protection', '1; mode=block');
res.header('X-Content-Type-Options', 'nosniff');
res.header('Strict-Transport-Security', 'max-age=63072000');
res.setHeader('Content-Type', 'application/json');
app.disable('x-powered-by');
let str = matchdata.match_url;
let live_url = str.replace('www', 'm');
axios({
method: 'GET',
url: live_url,
headers: {
'User-Agent': rua
}
}).then(function(response) {
$ = cheerio.load(response.data);
var title = $("h4.ui-header").text();
var update = $("div.cbz-ui-status").text();
var currentscore = $('span.ui-bat-team-scores').text();
var batsman = $('span.bat-bowl-miniscore').eq(0).text();
var batsmanrun = $('td[class="cbz-grid-table-fix "]').eq(6).text();
var ballsfaced = $('span[style="font-weight:normal"]').eq(0).text();
var fours = $('td[class="cbz-grid-table-fix "]').eq(7).text();
var sixes = $('td[class="cbz-grid-table-fix "]').eq(8).text();
var bowler = $('span.bat-bowl-miniscore').eq(2).text();
var bowlerover = $('td[class="cbz-grid-table-fix "]').eq(21).text();
var bowlerruns = $('td[class="cbz-grid-table-fix "]').eq(23).text();
var bowlerwickets = $('td[class="cbz-grid-table-fix "]').eq(24).text();
var partnership = $("span[style='color:#333']").eq(0).text();
var recentballs = $("span[style='color:#333']").eq(2).text();
var lastwicket = $("span[style='color:#333']").eq(1).text();
var runrate = $("span[class='crr']").eq(0).text();
var commentary = $("p[class='commtext']").text();
var livescore = ({
title: title || "Data Not Found",
update: update || "Data Not Found",
current: currentscore || "Data Not Found",
batsman: batsman || "Data Not Found",
batsmanrun: batsmanrun || "Data Not Found",
ballsfaced: ballsfaced || "Data Not Found",
fours: fours || "Data Not Found",
sixes: sixes || "Data Not Found",
bowler: bowler || "Data Not Found",
bowlerover: bowlerover || "Data Not Found",
bowlerruns: bowlerruns || "Data Not Found",
bowlerwickets: bowlerwickets || "Data Not Found",
partnership: partnership || "Data Not Found",
recentballs: recentballs || "Data Not Found",
lastwicket: lastwicket || "Data Not Found",
runrate: runrate || "Data Not Found",
commentary: commentary || "Data Not Found"
});
console.log("User-Agent:", rua);
res.send(JSON.stringify(livescore, null, 4));
console.log(livescore);
}).catch(function(error) {
if (!error.response) {
console.log('API URL is Missing');
res.json('API URL is Missing');
} else {
console.log('Something Went Wrong - Enter the Correct API URL');
res.json('Something Went Wrong - Enter the Correct API URL');
}
});
});
app.get('/score', function(req, res) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Access-Control-Allow-Headers,Content-Type,Access-Control-Allow-Methods, Authorization, X-Requested-With');
res.header('Access-Control-Allow-Methods', 'GET');
res.header('X-Frame-Options', 'DENY');
res.header('X-XSS-Protection', '1; mode=block');
res.header('X-Content-Type-Options', 'nosniff');
res.header('Strict-Transport-Security', 'max-age=63072000');
res.setHeader('Content-Type', 'application/json');
app.disable('x-powered-by');
const match_url = req.query.url;
let str = match_url;
let live_url = str.replace('www', 'm');
axios({
method: 'GET',
url: live_url,
headers: {
'User-Agent': rua
}
}).then(function(response) {
$ = cheerio.load(response.data);
var title = $("h4.ui-header").text();
var update = $("div.cbz-ui-status").text();
var currentscore = $('span.ui-bat-team-scores').text();
var batsman = $('span.bat-bowl-miniscore').eq(0).text();
var batsmanrun = $('td[class="cbz-grid-table-fix "]').eq(6).text();
var ballsfaced = $('span[style="font-weight:normal"]').eq(0).text();
var fours = $('td[class="cbz-grid-table-fix "]').eq(7).text();
var sixes = $('td[class="cbz-grid-table-fix "]').eq(8).text();
var bowler = $('span.bat-bowl-miniscore').eq(2).text();
var bowlerover = $('td[class="cbz-grid-table-fix "]').eq(21).text();
var bowlerruns = $('td[class="cbz-grid-table-fix "]').eq(23).text();
var bowlerwickets = $('td[class="cbz-grid-table-fix "]').eq(24).text();
var partnership = $("span[style='color:#333']").eq(0).text();
var recentballs = $("span[style='color:#333']").eq(2).text();
var lastwicket = $("span[style='color:#333']").eq(1).text();
var runrate = $("span[class='crr']").eq(0).text();
var commentary = $("p[class='commtext']").text();
var livescore = ({
title: title || "Data Not Found",
update: update || "Data Not Found",
current: currentscore || "Data Not Found",
batsman: batsman || "Data Not Found",
batsmanrun: batsmanrun || "Data Not Found",
ballsfaced: ballsfaced || "Data Not Found",
fours: fours || "Data Not Found",
sixes: sixes || "Data Not Found",
bowler: bowler || "Data Not Found",
bowlerover: bowlerover || "Data Not Found",
bowlerruns: bowlerruns || "Data Not Found",
bowlerwickets: bowlerwickets || "Data Not Found",
partnership: partnership || "Data Not Found",
recentballs: recentballs || "Data Not Found",
lastwicket: lastwicket || "Data Not Found",
runrate: runrate || "Data Not Found",
commentary: commentary || "Data Not Found"
});
console.log("User-Agent:", rua);
res.send(JSON.stringify(livescore, null, 4));
console.log(livescore);
}).catch(function(error) {
if (!error.response) {
console.log('API URL is Missing');
res.json('API URL is Missing');
} else {
console.log('Something Went Wrong - Enter the Correct API URL');
res.json('Something Went Wrong - Enter the Correct API URL');
}
});
});
var port = 3000;
app.listen(port, function() {
console.log('listening on port ' + port);
});