Skip to content

Commit

Permalink
Refine sponsors count logic and enhance sponsor summary extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Nov 26, 2024
1 parent e28b928 commit 0332b5c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Account < ApplicationRecord
before_save :set_sponsors_count

def set_sponsors_count
self.sponsors_count = total_sponsors
self.sponsors_count = total_sponsors == 0 ? sponsorships_as_maintainer.count : total_sponsors
self.sponsorships_count = sponsorships_as_funder.count
self.active_sponsorships_count = sponsorships_as_funder.active.count
end
Expand Down Expand Up @@ -105,18 +105,21 @@ def scrape_sponsored_page
}
end

sponsors = doc.at_css('#sponsors')&.css('.avatar')&.map { |avatar| avatar['alt'] } || []

c4 = doc.at('h4:contains("Current sponsors")')
current_sponsors = c4&.at('span.Counter')&.text&.delete(',') || 0

p4 = doc.at('h4:contains("Past sponsors")') || doc.at('h5:contains("Past sponsors")')
past_sponsors = p4&.at('span.Counter')&.text&.delete(',') || 0

if current_sponsors.zero? && past_sponsors.zero?
sponsor_summary = doc.at_css('p.f3-light.color-fg-muted.mb-3')&.text&.strip
total_sponsors_match = sponsor_summary&.match(/(\d+)\s+sponsors/)
current_sponsors = total_sponsors_match[1].to_i if total_sponsors_match
end

update sponsor_profile: {
bio: bio,
featured_works: featured_works,
sponsors: sponsors,
current_sponsors: current_sponsors,
past_sponsors: past_sponsors
}, last_synced_at: Time.now
Expand Down

0 comments on commit 0332b5c

Please sign in to comment.