Skip to content

Commit

Permalink
Merge pull request matryer#1470 from JimmyJoo/master
Browse files Browse the repository at this point in the history
Update github-contribution.10m.rb
  • Loading branch information
matryer authored Dec 11, 2020
2 parents 1320ac3 + 22cbf93 commit 16f4393
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions Dev/GitHub/github-contribution.10m.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ module GitHubContribution

class Contribution < Struct.new(:username, :contributed_on, :count)
RE_CONTRIBUTION = %r|<rect class="day" .+ data-count="(\d+)" data-date="(\d\d\d\d-\d\d-\d\d)"/>|

def self.find_all_by(username:)
[].tap do |contributions|
html = URI.send(:open, url_for(username: username)) { |f| f.read }

today = Date.parse(DateTime.now.to_s).to_s
year = today.split("-")[0];
html = URI.send(:open, "https://github.com/users/#{username}/contributions?to=#{today}#year-link-#{year}") { |f| f.read };
html.scan(RE_CONTRIBUTION) do |count, date|
contributions << Contribution.new(username, Date.parse(date), count.to_i)
end
Expand All @@ -103,10 +103,6 @@ def icon
else ':deciduous_tree:'
end
end

def self.url_for(username:)
"https://github.com/users/#{username}/contributions"
end
end

class View
Expand All @@ -132,9 +128,9 @@ def contribution_text_for(contribution)
end

def contribution_activity_for(contribution)
query = "from=#{contribution.contributed_on}"
query = "to=#{contribution.contributed_on}"
fragment = "year-link-#{contribution.contributed_on.year}"

"https://github.com/#{contribution.username}?#{query}##{fragment}"
end
end
Expand Down

0 comments on commit 16f4393

Please sign in to comment.