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

Fixed incorrect badge count if there's no gold badge #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kashifo
Copy link

@kashifo kashifo commented Nov 30, 2024

I wanted to use this widget in my profile, but the badge count was incorrectly displaying, it was because i don't have gold badge, but i have silver and bronze badges, so the previous code was setting bronze count into gold count.

I wanted to use this widget in my profile, but the badge count was incorrectly displaying, it was because i don't have gold badge, but i have silver and bronze badges, so the previous code was setting bronze count into gold count.
Copy link

vercel bot commented Nov 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
github-stackoverflow-readme ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 30, 2024 1:34am

Copy link
Owner

@krishnaacharyaa krishnaacharyaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your time @kashifo, just some small reviews, rest looks good, please upload photo with this change for missing badges and for the user who has all the badges

const $ = cheerio.load(html);

const detailsDiv = $("div.d-flex.flex__fl-equal.fw-wrap.gs24").first();
const badgeDivs = detailsDiv.find("div.fs-title"); 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this 1? compilation isn't failing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a typo, I had it fixed in the immediate next commit

const bronzeBadges = detailsDiv.find("div.badge-bronze").text().trim();

// If class names are not found or not reliable, use text content as a fallback
if (!goldBadges || !silverBadges || !bronzeBadges) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any one is not available why are we processing for all ? any reason.
Let's say goldbadges is not there silverBadges and bronzeBadges exists.
Then we are recalculating for silverbadges and bronzebadges even. can we try to optimize this , or any particular reason this is written this way?

@kashifo
Copy link
Author

kashifo commented Dec 5, 2024

Hey @krishnaacharyaa ,
Appreciate reviewing, I have changed code a few more times in my fork, and tested multiple approaches in my local node.js server, none of them seem to work in all scenarios because we are scraping the web page - That's the reason I didn't request for pull requests of my further commits.

Here's an idea which works properly, Shall I integrate StackOverflow's API?

I was wondering why you're scraping instead of using their API, then I found out myself that you want to display your reach which is great, which is not available in API.

So, shall we use the API for all other values, use scraping only for getting the reach value?

@kashifo
Copy link
Author

kashifo commented Dec 15, 2024

Hey @krishnaacharyaa , Appreciate reviewing, I have changed code a few more times in my fork, and tested multiple approaches in my local node.js server, none of them seem to work in all scenarios because we are scraping the web page - That's the reason I didn't request for pull requests of my further commits.

Here's an idea which works properly, Shall I integrate StackOverflow's API?

I was wondering why you're scraping instead of using their API, then I found out myself that you want to display your reach which is great, which is not available in API.

So, shall we use the API for all other values, use scraping only for getting the reach value?

@krishnaacharyaa Have been waiting for your reply on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants