mirror of
https://github.com/projekteuler/projekteuler.git
synced 2025-12-10 08:46:41 +01:00
Merge pull request #151 from projekteuler/problem_pull_fix
Fix CSV reading in problem pull
This commit is contained in:
commit
67dc2e6813
@ -7,13 +7,13 @@ class PullProblemsJob < ApplicationJob
|
||||
PULL_URL = "https://projecteuler.net/minimal=problems;csv"
|
||||
|
||||
def perform
|
||||
csv = CSV.parse(URI.open(PULL_URL), headers: [:id, :title, :date_published, :date_last_updated, :solved_by])
|
||||
csv = CSV.parse(URI.open(PULL_URL), headers: :first_row)
|
||||
csv.each do |row|
|
||||
id = row[:id].to_i
|
||||
last_updated = Time.at(row[:date_last_updated].to_i)
|
||||
id = row["ID"].to_i
|
||||
last_updated = Time.at(row["Updated"].to_i)
|
||||
problem = Problem.where(id: id).first_or_create!
|
||||
if problem.pulled_at.nil? or problem.pulled_at < last_updated
|
||||
original_title = row[:title]
|
||||
original_title = row["Description"]
|
||||
problem.update(original_title: original_title)
|
||||
# Don't update pulled_at yet until we also successfully pulled the original_content
|
||||
PullProblemContentJob.perform_later problem
|
||||
|
||||
@ -4,6 +4,7 @@ require 'csv'
|
||||
class PullProblemsJobTest < ActiveJob::TestCase
|
||||
test "should update problem count and titles" do
|
||||
csv_string = CSV.generate do |csv|
|
||||
csv << ["ID", "Description", "Published", "Updated", "Solved By"]
|
||||
csv << [1, "Title of problem 1", 4.days.ago.to_i, 2.days.ago.to_i, 123]
|
||||
csv << [2, "Title of problem 2", 4.days.ago.to_i, 2.days.ago.to_i, 123]
|
||||
csv << [3, "Title of problem 3", 4.days.ago.to_i, 2.days.ago.to_i, 123]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user