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

Contributors API #219

Open
zzak opened this issue Feb 2, 2023 · 0 comments
Open

Contributors API #219

zzak opened this issue Feb 2, 2023 · 0 comments

Comments

@zzak
Copy link
Member

zzak commented Feb 2, 2023

It would be nice if I could fetch the total number of contributors in a time window.

Currently, I'm parsing using Nokogiri, but I guess that's fine.

Sample code fwiw:

class Contributors
  attr_accessor :body, :start_date, :end_date, :total
  def initialize(start_date, end_date)
    @start_date = start_date.strftime("%Y%m%d")
    @end_date = end_date.strftime("%Y%m%d")
    @body = fetch
    @total = extract_total
  end

  def url
    "https://contributors.rubyonrails.org/contributors/in-time-window/#{@start_date}-#{@end_date}"
  end

  def fetch
    uri = URI.parse(url)
    body = uri.open.read
    return Nokogiri::HTML(body)
  end

  def extract_total
    xpath = "//span[@class=\"listing-total\"][1]"
    text = @body.xpath(xpath.to_s).first.content
    return text.match(/\d+/)
  end
end
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

No branches or pull requests

1 participant