Skip to content

Commit

Permalink
Merge pull request #1 from danilosp1/docs
Browse files Browse the repository at this point in the history
docs
  • Loading branch information
danilosp1 committed Nov 30, 2023
2 parents bdddba5 + 8055585 commit b69baba
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pages/api/times/v1/[times].js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const action = async (request, response) => {
try {
const teams = await getTeamsBySeries(request.query.times);

console.log(teams)

response.status(200).json(teams);
} catch (error) {
if(error instanceof BaseError){
Expand Down
66 changes: 66 additions & 0 deletions pages/docs/doc/brasileirao.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"tags": [
{
"name": "TIMES",
"description": "Informação dos times da seleção no Brasileirão"
}
],

"paths": {
"/times/v1/{serie}" : {
"get" : {
"tags" : ["TIMES"],
"summary" : "Retorna os times no Brasileirão",
"description" :"Informação dos times da seleção na série especificada",
"parameters": [
{
"name": "série",
"description": "Série que você deseja visualizar os times\n",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses" : {
"200": {
"description" : "Success",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/Time"
}
}
}
}
}
}
}
}
},

"components" : {
"schemas" : {
"Time" : {
"title" : "Time",
"required" : ["name", "score"],
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
},
"score" : {
"type" : "string"
}
} ,
"example" : {
"name" : "Palmeiras",
"score" : "66"
}
}
}
}
}
1 change: 1 addition & 0 deletions pages/sitemap.xml/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const getDocs = () => {
'ISBN',
'CPTEC',
'PIX',
'Times-Brasileirao',
];
};

Expand Down
26 changes: 18 additions & 8 deletions services/times-brasileirao/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const https = require('https');
const axios = require('axios');
import { parse } from 'node-html-parser';

let cacheAgent;

Expand All @@ -14,17 +13,28 @@ function getAgent() {

export async function getTeamsBySeries(series) {
const agent = getAgent();
let url;

// As URLs são referentes a arquivos JSON armazenados no drive, gerados frequentemente a partir de um script de scraping no site
// https://ge.globo.com/futebol/brasileirao-serie-{serie}/, utilizando Python
try {
const response = await axios.get(`https://ge.globo.com/futebol/brasileirao-serie-${series}/`).then(res => res.data);
switch (series) {
case 'a':
url = 'https://drive.google.com/uc?export=download&id=1Xx325sVS3YJ3qV_UdQumAT6nXPlCpigP';
break;
case 'b':
url = 'https://drive.google.com/uc?export=download&id=1WZLEFg9QavI1l0HshZ7PmM_wc-TIKzVx';
break;

console.log(response);
default:
url = 'https://drive.google.com/uc?export=download&id=1Xx325sVS3YJ3qV_UdQumAT6nXPlCpigP';
break;
}

const teams = [];
root.querySelectorAll(".classificacao__pontos-corridos .tabela__equipes tbody tr .classificacao__equipes--nome").forEach(element => {
teams.push(element.text.trim());
});
const response = await axios.get(url);
const data = response.data;

return response;
return data;
} catch (error) {
console.error('Erro ao obter times: ', error);
throw error;
Expand Down

0 comments on commit b69baba

Please sign in to comment.