Skip to content

Commit

Permalink
Add method to import ESD projects from CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Mar 6, 2025
1 parent 5d2e5d9 commit a2824b2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ def self.import_from_csv
end
end

def self.import_esd_projects
url = 'https://raw.githubusercontent.com/open-energy-transition/open-esd-analysis/refs/heads/main/esd_list.csv'

conn = Faraday.new(url: url) do |faraday|
faraday.response :follow_redirects
faraday.adapter Faraday.default_adapter
end

response = conn.get
return unless response.success?
csv = response.body
csv_data = CSV.new(csv, headers: true)

csv_data.each do |row|
puts "Processing #{row['project_name']}"
project_url = row['project_url']
id = project_url.split('/').last
project = Project.find_by(id: id)
next unless project.present?
project.update(esd: true)
end
end

def self.import_education
url = 'https://raw.githubusercontent.com/protontypes/open-sustainable-technology/refs/heads/main/education.md'

Expand Down

0 comments on commit a2824b2

Please sign in to comment.