Compare commits

...

10 Commits

Author SHA1 Message Date
Đạt
9b3f459e2a
Update link 2024-04-30 15:31:14 +07:00
ttD4T
26bcb8f30f Update README 2023-06-19 10:00:37 +07:00
ttD4T
02d96ddf88 Config url & update README 2023-06-19 09:53:59 +07:00
ttD4T
278023bcd2 Update realtime 2023-06-14 18:23:07 +07:00
ttD4T
a9fda0d509 Change api link 2023-06-14 00:17:59 +07:00
ttD4T
ba6fac22fb Change title results 2023-06-13 22:29:03 +07:00
ttD4T
6040461666 Change url web-scraped 2023-06-13 22:23:57 +07:00
DDatj
aa2da5ecbd update host 2022-11-15 11:29:38 +07:00
d4rtj
9dfc86a044 update array 2022-10-28 22:15:01 +07:00
d4rtj
69715516d6 change names 2022-10-28 12:11:00 +07:00
6 changed files with 140 additions and 116 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
URL=https://az24.vn/xsmb-sxmb-xo-so-mien-bac.html
#https://xosoketqua.com/xsmb-xo-so-mien-bac.html[DA TUNG SU DUNG]

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/node_modules
package-lock.json
.env

View File

@ -1,19 +1,17 @@
# api-xsmb-today
> take infor from api by https://api-xsmb-today.herokuapp.com/v1
>
> web-scraped from https://xosoketqua.com/xsmb-xo-so-mien-bac.html
> take info from api by [https://api-xsmb.cyclic.app/api/v1](https://api-xsmb-today.onrender.com/api/v1)
---
| Keys | Type |
| ---- | ------ |
| time | String |
| G.ĐB | String |
| G.1 | String |
| G.2 | String |
| G.3 | String |
| G.4 | String |
| G.5 | String |
| G.6 | String |
| G.7 | String |
| Keys | Type |
| ---- | ------------ |
| time | Array String |
| ĐB | Array String |
| G1 | Array String |
| G2 | Array String |
| G3 | Array String |
| G4 | Array String |
| G5 | Array String |
| G6 | Array String |
| G7 | Array String |

View File

@ -1,124 +1,147 @@
const axios = require('axios');
const cheerio = require('cheerio');
require('dotenv').config();
const url = 'https://xosoketqua.com/xsmb-xo-so-mien-bac.html';
const url = process.env.URL;
class MainController {
getAll = async (req, res) => {
const numbers = [];
const names = [];
const times = [];
const objTimesNames = {};
const obj = {};
const results = {};
try {
await axios(url).then(response => {
const html = response.data;
const $ = cheerio.load(html); // sử dụng giống jQuery
axios(url, {
method: 'GET',
})
.then((response) => {
const html = response.data;
const $ = cheerio.load(html); // sử dụng giống jQuery
$('table:nth-child(1)', html)
// .first()
.each(function () {
$(this)
.find('td > span.div-horizontal')
.each(function () {
numbers.push($(this).text());
});
$('table:nth-child(1)', html)
.first()
.each(function () {
$(this)
.find('td.v-giai > span ')
.each(function () {
numbers.push($(this).text());
});
// console.log(numbers);
$(this)
.find('tr > td:first-child')
.each(function (i) {
const name = $(this).text();
$(this)
.find('tr > td:first-child')
.each(function (i) {
const name = $(this).text();
if (name !== 'Mã ĐB') {
// for (let i = 0; i < names.length; i++) {
if (names.includes(name)) {
return;
} else {
names.push(name);
if (!name.includes('Mã ĐB')) {
// for (let i = 0; i < names.length; i++) {
if (names.includes(name)) {
return;
} else {
names.push(
name
.replace('Giải', 'G')
.split(' ')
.join('')
);
}
// }
}
// }
}
});
});
if (numbers.length > 0) {
for (let i = 0; i < names.length; i++) {
objTimesNames[names[0]] = numbers[0];
objTimesNames[names[1]] = numbers[1];
objTimesNames[names[2]] = [numbers[2], numbers[3]];
objTimesNames[names[3]] = [
numbers[4],
numbers[5],
numbers[6],
numbers[7],
numbers[8],
numbers[9],
];
objTimesNames[names[4]] = [
numbers[10],
numbers[11],
numbers[12],
numbers[13],
];
objTimesNames[names[5]] = [
numbers[14],
numbers[15],
numbers[16],
numbers[17],
numbers[18],
numbers[19],
];
objTimesNames[names[6]] = [
numbers[20],
numbers[21],
numbers[22],
];
objTimesNames[names[7]] = [
numbers[23],
numbers[24],
numbers[25],
numbers[26],
];
});
});
numbers.splice(0, 1); // xóa phần tử đầu tiên
if (numbers.length > 0) {
for (let i = 0; i < names.length; i++) {
results[names[0]] = [
numbers[0] ? numbers[0] : 'Đang cập nhật',
];
results[names[1]] = [
numbers[1] ? numbers[1] : 'Đang cập nhật',
];
results[names[2]] = [
numbers[2] ? numbers[2] : 'Đang cập nhật',
numbers[3] ? numbers[3] : 'Đang cập nhật',
];
results[names[3]] = [
numbers[4] ? numbers[4] : 'Đang cập nhật',
numbers[5] ? numbers[5] : 'Đang cập nhật',
numbers[6] ? numbers[6] : 'Đang cập nhật',
numbers[7] ? numbers[7] : 'Đang cập nhật',
numbers[8] ? numbers[8] : 'Đang cập nhật',
numbers[9] ? numbers[9] : 'Đang cập nhật',
];
results[names[4]] = [
numbers[10] ? numbers[10] : 'Đang cập nhật',
numbers[11] ? numbers[11] : 'Đang cập nhật',
numbers[12] ? numbers[12] : 'Đang cập nhật',
numbers[13] ? numbers[13] : 'Đang cập nhật',
];
results[names[5]] = [
numbers[14] ? numbers[14] : 'Đang cập nhật',
numbers[15] ? numbers[15] : 'Đang cập nhật',
numbers[16] ? numbers[16] : 'Đang cập nhật',
numbers[17] ? numbers[17] : 'Đang cập nhật',
numbers[18] ? numbers[18] : 'Đang cập nhật',
numbers[19] ? numbers[19] : 'Đang cập nhật',
];
results[names[6]] = [
numbers[20] ? numbers[20] : 'Đang cập nhật',
numbers[21] ? numbers[21] : 'Đang cập nhật',
numbers[22] ? numbers[22] : 'Đang cập nhật',
];
results[names[7]] = [
numbers[23] ? numbers[23] : 'Đang cập nhật',
numbers[24] ? numbers[24] : 'Đang cập nhật',
numbers[25] ? numbers[25] : 'Đang cập nhật',
numbers[26] ? numbers[26] : 'Đang cập nhật',
];
}
}
}
// $('.list-link', html)
// .find('h2 > a:last-child')
// .each(function () {
// const time = $(this).prop('innerHTML').split(' ')[1];
// $('.list-link', html)
// .find('h2 > a:last-child')
// .each(function () {
// const time = $(this).prop('innerHTML').split(' ')[1];
// // times.push(time);
// console.log(time);
// });
// times.push(time);
// console.log(time);
// });
// if (times.length > 0) {
// times.forEach(time => {
// for (let i = 0; i < names.length; i++) {
// objTimesNames[time] = [...names];
// }
// });
// }
const nowDay = new Date();
const calendar =
nowDay.getDate() +
'/' +
(nowDay.getMonth() + 1 < 10
? '0' + (nowDay.getMonth() + 1)
: nowDay.getMonth() + 1) +
'/' +
nowDay.getFullYear();
// console.log(nowDay.getHours() + ':' + nowDay.getMinutes());
// console.log(objTimesNames);
// if (times.length > 0) {
// times.forEach(time => {
// for (let i = 0; i < names.length; i++) {
// results[time] = [...names];
// }
// });
// }
const nowDay = new Date();
const calendar =
nowDay.getDate() +
'/' +
(nowDay.getMonth() + 1 < 10
? '0' + (nowDay.getMonth() + 1)
: nowDay.getMonth() + 1) +
'/' +
nowDay.getFullYear();
// console.log(nowDay.getHours() + ':' + nowDay.getMinutes());
// console.log(results);
const date = $('.class-title-list-link', html).first().find('a:last-child').text().split(' ')[1];
const date = $('div.tit-mien.clearfix.txt-center > div', html)
.first()
.find('a:last-child')
.text()
.split(' ')[2];
res.status(200).json({
countNumbers: numbers.length,
time: date,
objTimesNames,
res.status(200).json({
countNumbers: numbers.length,
time: date,
results,
});
})
.catch((err) => {
console.log(err);
return res.status(500).json({ msg: err });
});
});
} catch (e) {
res.status(500).json({ msg: e });
}

View File

@ -2,7 +2,7 @@
"name": "apixsmb",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js",

View File

@ -1,7 +1,7 @@
const routeV1 = require('./v1/index');
const routes = app => {
app.use('/v1', routeV1);
app.use('/api/v1', routeV1);
};
module.exports = routes;