Skip to content

Commit

Permalink
Get donation data from Notion
Browse files Browse the repository at this point in the history
  • Loading branch information
patbl committed Jan 28, 2024
1 parent 6472e52 commit 451352b
Show file tree
Hide file tree
Showing 11 changed files with 1,289 additions and 563 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
build
TAGS
log
lib/node_modules
60 changes: 15 additions & 45 deletions lib/donation.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
class Donation
ORGANIZATION_URLS = {
"80,000 Hours" => "http://80000hours.org/",
"The Humane League" => "http://www.thehumaneleague.com/",
"Animal Charity Evaluators" => "http://www.animalcharityevaluators.org/",
"St. Olaf College" => "http://stolaf.edu/",
"Centre for Effective Altruism" => "https://www.centreforeffectivealtruism.org/",
".impact (now Rethink Charity)" => "https://www.rethinkprojects.org/",
"Mercy for Animals" => "http://www.mercyforanimals.org/",
"Effective Altruism Community Fund" => "https://app.effectivealtruism.org/funds/ea-community",
"Long-Term Future Fund" => "https://app.effectivealtruism.org/funds/far-future",
"MIRI" => "https://intelligence.org/",
"AIDS/LifeCycle" => "https://www.aidslifecycle.org/",
"ALLFED" => "http://allfed.info/",
"Global Catastrophic Risk Institute" => "https://gcrinstitute.org/",
"Berkeley REACH" => "https://www.berkeleyreach.org/",
"Berkeley Existential Risk Initiative" => "https://existence.org/",
"Guarding Against Pandemics" => "https://www.againstpandemics.org/",
"Rethink Priorities" => "https://www.rethinkpriorities.org/",
"Donor Lottery" => "https://app.effectivealtruism.org/lotteries",
}

ATTRIBUTES = [
{name: :organization},
{name: :date},
{name: :amount},
{name: :is_grant, new_name: :grant?, default: false},
{name: :is_daf_contribution, new_name: :daf_contribution?, default: false},
{name: :note, default: nil},
{name: :ineffectual, new_name: :ineffectual?, default: false},
{name: :hidden, new_name: :hidden?, default: false},
]
def initialize(values)
ATTRIBUTES.each do |attrs|
original_name = attrs.fetch(:name)
new_name = attrs.fetch(:new_name, original_name)
instance_variable_set(:"@#{original_name}", values.fetch(original_name) { attrs.fetch(:default) })
value = values.fetch(original_name) { attrs.fetch(:default) }
if new_name == :date
value = Date.parse(value)
end
instance_variable_set(:"@#{original_name}", value)
define_singleton_method(new_name) do
instance_variable_get(:"@#{original_name}")
end
Expand Down Expand Up @@ -65,34 +46,23 @@ def url
end

def organizations
@organizations ||= YAML.safe_load(File.open("lib/organizations.yaml"))
end

def ineffectual_amount_donated
ineffectual? ? amount_donated_by_me : 0
end

def possibly_effectual_amount_donated
ineffectual? ? 0 : amount_donated_by_me
@organizations ||= File.read("lib/organizations.json")
.then { |json| JSON.parse(json) }
.index_by { |org| org.fetch("name") }
end

def css_class
if ineffectual?
"text-red-500"
elsif grant?
if grant?
"text-grey-dark"
end
end

def self.load_donations(show_hidden:)
YAML.safe_load_file("lib/donations.yaml", permitted_classes: [Date]).map { |args|
Donation.new(args.symbolize_keys)
}
.select { |donation| show_hidden || !donation.hidden? }
.sort_by { |donation|
[donation.date, donation.organization, donation.amount, donation.note]
}
.reverse
def self.load_donations(*)
File.read("lib/donations.json")
.then { |json| JSON.parse(json) }
.map { |donation| Donation.new(donation.symbolize_keys) }
.sort_by { |donation| [donation.date, donation.organization, donation.amount, donation.note] }
.reverse
end

def self.total_donated_by_me(show_hidden:)
Expand Down
Loading

0 comments on commit 451352b

Please sign in to comment.