From f613717852335f7135a3be5a3da1fd3fed46ea7a Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sat, 13 May 2023 11:48:24 +1000 Subject: [PATCH] Fix movie backfill task --- Rakefile | 7 +++++++ slices/admin/repos/movie_repo.rb | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/Rakefile b/Rakefile index f0db9f7..8ab2d3c 100644 --- a/Rakefile +++ b/Rakefile @@ -17,8 +17,15 @@ namespace :blog do movies = movie_repo.listing movies.each do |movie| + record = movie_repo.by_url(url: movie.url) + + next unless record.imdb_id.nil? + page = Down.download(movie.url) match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/) + + next unless match + imdb_id = match[1] movie_repo.update(movie.id, {imdb_id: imdb_id}) diff --git a/slices/admin/repos/movie_repo.rb b/slices/admin/repos/movie_repo.rb index 599d287..fc81dc1 100644 --- a/slices/admin/repos/movie_repo.rb +++ b/slices/admin/repos/movie_repo.rb @@ -7,6 +7,10 @@ module Admin movies.where(title: title, year: year).one end + def by_url(url:) + movies.where(url: url).one + end + def listing movies.order(Sequel.lit("year desc")).to_a end