Add IMDB ID to movies
This commit is contained in:
23
Rakefile
23
Rakefile
@@ -2,12 +2,29 @@
|
||||
|
||||
require "dotenv"
|
||||
require "hanami/rake_tasks"
|
||||
require "down"
|
||||
|
||||
namespace :blog do
|
||||
task :load_environment do
|
||||
Dotenv.load("/home/blog/current/.env.production")
|
||||
end
|
||||
|
||||
task :backfill_movie_imdb_ids => ["blog:load_environment"] do
|
||||
require "hanami/prepare"
|
||||
|
||||
movie_repo = Admin::Container["repos.movie_repo"]
|
||||
|
||||
movies = movie_repo.listing
|
||||
|
||||
movies.each do |movie|
|
||||
page = Down.download(movie.url)
|
||||
match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)
|
||||
imdb_id = match[1]
|
||||
|
||||
movie_repo.update(movie.id, {imdb_id: imdb_id})
|
||||
end
|
||||
end
|
||||
|
||||
task :load_from_letterboxd => ["blog:load_environment"] do
|
||||
require "hanami/prepare"
|
||||
require "scraperd"
|
||||
@@ -15,15 +32,13 @@ namespace :blog do
|
||||
client = Scraperd::Base.new
|
||||
activities = client.fetch('dnitza')
|
||||
|
||||
repo = Adamantium::Container["repos.movie_repo"]
|
||||
create_command = Admin::Container["commands.movies.create"]
|
||||
|
||||
activities.each do |activity|
|
||||
|
||||
title = CGI.unescapeHTML(activity.title)
|
||||
|
||||
next if repo.by_title_and_year(title: title, year: activity.year)
|
||||
|
||||
repo.create({
|
||||
create_command.({
|
||||
title: title,
|
||||
year: activity.year,
|
||||
url: activity.film_link,
|
||||
|
Reference in New Issue
Block a user