Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] GuildStats Graph per Creature #6

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ STORAGE_BUCKET=tibiatoptrumps.appspot.com
MESSAGING_SENDER_ID=726362321155
APP_ID=1:726362321155:web:97eee67d1e474e52473936
MEASUREMENT_ID=G-YD7ENY2LL3
PRIVATE_KEY_ID=055d43aae0be25c38a37d6fd7b3cac0956c44c8b
UNIVERSE_DOMAIN=googleapis.com
CLIENT_CERT_URL=https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-rn9hj%40tibiatoptrumps.iam.gserviceaccount.com
AUTH_CERT_PROVIDER=https://www.googleapis.com/oauth2/v1/certs
PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDPhmdZZzKTm5JC\nnJW8x1ZGxZWWWVWAmYcW+X5COa42Lp+8kXFHzillWpB9z0VxiXL6/KI2gFUntVlY\nyccQKj4GvO5pSpu43+PHnudrqnH3KdsMxC/CFxvkPftUH00m9buS4MYzFhyN/wt4\ny8CMPaX/JX2MQMwBziFdSuu7D9gDpPFShxGMWu+KzEjWGoMVREW4svdCZHf9JI/G\n28aEPMw3MvHNc65JfTT67td1eMVLPh6zBQ+IqLM+hBlS0hkKarGSlgLkVkuWkjyk\nxfsN4zEfwC7NGwvOPAA7YyZrPD9DbJX8HrDCuQ5bT3AJF0KOVEMshgLJPcRnbY9J\nUdH+p9r5AgMBAAECggEAKL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iPdB92EW48VXvmVW\n1pEP/fkUhtmrmcV9dLLqRlZG6MQgKDPiHhKbYzaGrNsNk0pvXx6a1SUP8UbMRmb3\ns9nsEHsJRpUk2udvlgHMsSkgTNsYJyQ/ZAyR9AkKMImQi4crJUdRVscXSJDFIJL6\nEDzH4kQFo5i6tv1QhucsRkU6\n-----END PRIVATE KEY-----\n
CLIENT_EMAIL=firebase-adminsdk-rn9hj@tibiatoptrumps.iam.gserviceaccount.com
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ yarn-error.log*
# Local Netlify folder
.netlify
.vercel

.serverless
5 changes: 5 additions & 0 deletions event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"pathParameters": {
"boss": "Barbaria"
}
}
70 changes: 0 additions & 70 deletions functions/duplicated-bosses.js

This file was deleted.

85 changes: 85 additions & 0 deletions functions/duplicated-bosses/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Import the required modules

// NEEDS to be fixed, not working at the moment
const axios = require("axios");
const cheerio = require("cheerio");

async function getDuplicatedBosses(url) {
try {
const url = "https://www.tibiabosses.com/stats/?world=Venebra&mode=3";

const response = await axios.get(url);
const $ = cheerio.load(response.data);

const bosses = [
{
name: "White Pale",
cities: ["Edron", "Darashia", "Liberty Bay"],
count: 3,
},
{
name: "Rotworm Queen",
cities: ["Darashia", "Ab'dendriel", "Edron", "Liberty Bay"],
count: 4,
},
];

const result = [];

bosses.forEach((boss) => {
const bossDiv = $(`img[alt="${boss.name}"]`).parent();
const cityDivs = bossDiv.nextAll().slice(0, boss.count);

cityDivs.each((index, el) => {
const city = boss.cities[index];
const lastSeen = $(el).text().trim();
const chanceDiv = $(el).next();
// Get the chance value based on the color
let chanceText = chanceDiv.css("color");
let chances = 0;

if (chanceText === "green") {
chances = 1;
} else if (chanceText === "blue") {
chances = 0.01;
} else {
chances = 0;
}

result.push({
name: boss.name,
city: city,
lastSeen: lastSeen,
chance: chances,
});
});
});

return result;
} catch (error) {
console.error("Error fetching data:", error.message);
return [];
}
}

const handler = async (event, context) => {
try {
const bossList = await getDuplicatedBosses();
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*", // Allow requests from any origin
"Access-Control-Allow-Headers": "Content-Type",
},
body: JSON.stringify(bossList),
};
} catch (error) {
console.error("Error:", error);
return {
statusCode: error.statusCode || 500,
body: JSON.stringify(error),
};
}
};

module.exports = { handler };
77 changes: 77 additions & 0 deletions functions/guild-stats-graph/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Import the required modules
const cheerio = require("cheerio");
const chromium = require('chrome-aws-lambda');

async function getGuildStatsGraph(boss) {
try {
// console.log("1 - Started : ", new Date())
const url = `https://guildstats.eu/bosses?world=Venebra&monsterName=${boss}`;

const browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
});

// console.log("2 - Browser : ", new Date())

const page = await browser.newPage();
// console.log("3 - Page : ", new Date())

await page.goto(url, { waitUntil: "networkidle2" });
// console.log("4 - GoTo : ", new Date())

const html = await page.content();
// console.log("5 - HTML : ", new Date())

const $ = cheerio.load(html);
// console.log("6 - Load : ", new Date())

const data = [];
$(
'div[aria-label="A tabular representation of the data in the chart."] table tbody tr'
).each((index, element) => {
// console.log("6.1 - Each : ", new Date());
const tds = $(element).find("td");
const daysAfter = parseInt($(tds[0]).text(), 10);
const chance = parseFloat($(tds[1]).text());
if (data.some(item => item.daysAfter === daysAfter)) {
return;
}
data.push({ daysAfter, chance });
});
// console.log("7 - Data : ", new Date())
data.sort((a, b) => a.daysAfter - b.daysAfter);

// console.log("8 - Sorted : ", new Date())
return data;
} catch (error) {
console.error("Error fetching data:", error);
return [];
}
}

const handler = async (event, context) => {
try {
const boss = event.pathParameters.boss;
const graphData = await getGuildStatsGraph(boss);
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*", // Allow requests from any origin
"Access-Control-Allow-Headers": "Content-Type",
},
body: JSON.stringify(graphData),
};
} catch (error) {
console.error(error);
return {
statusCode: error.statusCode || 500,
body: JSON.stringify(error),
};
}
};

module.exports = { handler };
69 changes: 0 additions & 69 deletions functions/guild-stats.js

This file was deleted.

Loading