Skip to content

Commit

Permalink
Refactor attr name out
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneCurcuru committed Feb 5, 2024
1 parent 8ebfbdd commit 24db8df
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions assets/ruby/sponsor_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,46 @@ def normalize_href(base, href)
'fourth' => '.Silver-sponsors a',
'fifth' => '.Bronze-sponsors a'
}
DRUPAL_SPONSOR_CSS = {
DRUPAL_SPONSOR_CSS = { # TODO sponsor links are on separate page
'first' => '.sponsors--signature a',
'second' => '.view-display-id-attachment_6 a',
'third' => '.view-display-id-attachment_3 a',
'fourth' => '.view-display-id-attachment_1 a',
'community' => '.view-display-id-attachment_9 a'
}
DRUPAL_SPONSOR_PAGE = '.org-link a'
PYTHON_SPONSOR_CSS = { # TODO Uses ethicalads.io to disintermediate sponsor links/logos; requires custom processing
'first' => 'div[title="visionary Sponsors"] div[data-internal-year]',
'second' => 'div[title="sustainability Sponsors"] div[data-internal-year]',
'third' => 'div[title="maintaining Sponsors"] div[data-internal-year]',
'fourth' => 'div[title="contributing Sponsors"] div[data-internal-year]',
'fifth' => 'div[title="supporting Sponsors"] div[data-internal-year]',
'sixth' => 'div[title="partner Sponsors"] div[data-internal-year]',
'seventh' => 'div[title="participating Sponsors"] div[data-internal-year]',
'eighth' => 'div[title="associate Sponsors"] div[data-internal-year]'
}
FOUNDATION_MAP = {
'asf' => [ASF_SPONSOR_CSS, 'href'],
'numfocus' => [NUMFOCUS_SPONSOR_CSS, 'href'],
'osgeo' => [OSGEO_SPONSOR_CSS, 'href'],
'drupal' => [DRUPAL_SPONSOR_CSS, 'href'],
'python' => [PYTHON_SPONSOR_CSS, 'id']
}

# Scrape sponsor listing defined by css selectors
# @param io input stream of html to parse
# @param shortname of foundation map to parse
# @return hash of sponsors by approximate map-defined levels
def scrape_bycss(io, baseurl, selectors)
def scrape_bycss(io, foundation)
sponsors = {}
cssmap = FOUNDATION_MAP.fetch(foundation, nil)
doc = Nokogiri::HTML5(io)
body = doc.xpath('/html/body')
selectors.each do | key, selector |
cssmap[0].each do | key, selector |
nodelist = body.css(selector)
sponsors[key] = []
nodelist.each do | node |
sponsors[key] << node['href']
sponsors[key] << node[cssmap[1]]
end
end
return sponsors
Expand All @@ -81,9 +100,9 @@ def scrape_bycss(io, baseurl, selectors)
# ### #### ##### ######
# Main method for command line use
if __FILE__ == $PROGRAM_NAME
filename = '../../../sponsors-drupal.html'
filename = '../../../sponsors-asf.html'
baseurl = ''
io = File.open(filename)
sponsors = SponsorUtils.scrape_bycss(io, baseurl, SponsorUtils::DRUPAL_SPONSOR_CSS)
sponsors = SponsorUtils.scrape_bycss(io, 'asf')
puts JSON.pretty_generate(sponsors)
end

0 comments on commit 24db8df

Please sign in to comment.