Fix movie backfill task
This commit is contained in:
7
Rakefile
7
Rakefile
@@ -17,8 +17,15 @@ namespace :blog do
|
|||||||
movies = movie_repo.listing
|
movies = movie_repo.listing
|
||||||
|
|
||||||
movies.each do |movie|
|
movies.each do |movie|
|
||||||
|
record = movie_repo.by_url(url: movie.url)
|
||||||
|
|
||||||
|
next unless record.imdb_id.nil?
|
||||||
|
|
||||||
page = Down.download(movie.url)
|
page = Down.download(movie.url)
|
||||||
match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)
|
match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)
|
||||||
|
|
||||||
|
next unless match
|
||||||
|
|
||||||
imdb_id = match[1]
|
imdb_id = match[1]
|
||||||
|
|
||||||
movie_repo.update(movie.id, {imdb_id: imdb_id})
|
movie_repo.update(movie.id, {imdb_id: imdb_id})
|
||||||
|
@@ -7,6 +7,10 @@ module Admin
|
|||||||
movies.where(title: title, year: year).one
|
movies.where(title: title, year: year).one
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def by_url(url:)
|
||||||
|
movies.where(url: url).one
|
||||||
|
end
|
||||||
|
|
||||||
def listing
|
def listing
|
||||||
movies.order(Sequel.lit("year desc")).to_a
|
movies.order(Sequel.lit("year desc")).to_a
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user