diff --git a/Gemfile b/Gemfile index 2ea70b3..3ec1685 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,7 @@ gem "lastfm", "~> 1.27" gem "mail" gem "que" gem "connection_pool" +gem "omdb-api", require: false group :cli, :development do gem "hanami-reloader" diff --git a/Gemfile.lock b/Gemfile.lock index c5a741d..711a614 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,6 +48,11 @@ GIT GEM remote: https://rubygems.org/ specs: + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) addressable (2.8.4) public_suffix (>= 2.0.2, < 6.0) airbrussh (1.4.1) @@ -261,6 +266,7 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2023.0218.1) mini_mime (1.1.2) + minitest (5.18.0) multi_xml (0.6.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) @@ -292,6 +298,9 @@ GEM ogpr (1.1.0) nokogiri (~> 1.8) rest-client (~> 2.1.0) + omdb-api (1.4.3) + activesupport + httparty parallel (1.23.0) parser (3.2.2.1) ast (~> 2.4.1) @@ -419,6 +428,8 @@ GEM timecop (0.9.6) timeout (0.3.2) transproc (1.1.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unf (0.1.4) unf_ext unf_ext (0.0.8.2) @@ -466,6 +477,7 @@ DEPENDENCIES mail matrix ogpr + omdb-api pg pinboard! puma diff --git a/Rakefile b/Rakefile index 8ab2d3c..9b83d5f 100644 --- a/Rakefile +++ b/Rakefile @@ -9,29 +9,6 @@ namespace :blog 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| - 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}) - end - end - task :load_from_letterboxd => ["blog:load_environment"] do require "hanami/prepare" require "scraperd" diff --git a/app/decorators/movies/decorator.rb b/app/decorators/movies/decorator.rb new file mode 100644 index 0000000..662e5b1 --- /dev/null +++ b/app/decorators/movies/decorator.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: false + +# auto_register: false + +module Adamantium + module Decorators + module Movies + class Decorator < SimpleDelegator + + include Deps["clients.omdb"] + + def poster + omdb_record.poster + end + + def omdb_record + @omdb_record ||= omdb.call(imdb_id: imdb_id) + end + end + end + end +end diff --git a/app/repos/movie_repo.rb b/app/repos/movie_repo.rb index b0902e1..709e240 100644 --- a/app/repos/movie_repo.rb +++ b/app/repos/movie_repo.rb @@ -10,6 +10,24 @@ module Adamantium def by_title_and_year(title:, year:) movies.where(title: title, year: year).one end + + def from_the_archives(start_date:, end_date:) + # SELECT * FROM posts + # WHERE EXTRACT(month FROM "published_at") >= 2 + # WHERE EXTRACT(month FROM "published_at") <= 2+ + # AND EXTRACT(day FROM "published_at") > 20 + # AND EXTRACT(day FROM "published_at") < 27 + # AND post_type = 'post'; + + movies + .where { Sequel.extract(:year, :watched_at) >= start_date.year } + .where { Sequel.extract(:year, :watched_at) <= start_date.year } + .where { Sequel.extract(:month, :watched_at) >= start_date.month } + .where { Sequel.extract(:month, :watched_at) <= end_date.month } + .where { Sequel.extract(:day, :watched_at) >= start_date.day } + .where { Sequel.extract(:day, :watched_at) <= end_date.day } + .to_a + end end end end \ No newline at end of file diff --git a/app/templates/posts/show.html.slim b/app/templates/posts/show.html.slim index 55fa7b7..5a5ea39 100644 --- a/app/templates/posts/show.html.slim +++ b/app/templates/posts/show.html.slim @@ -40,6 +40,16 @@ article class="h-entry" div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 flex gap-4" div class="grow" hx-get="/post/top_tracks/#{post.slug}" hx-trigger="load" + - if past_movies.count > 0 + div class="max-w-prose mx-auto text-gray-600 dark:text-gray-200 mb-4" + h3 class="text-xl" Movies watched + div class="flex gap-4 pb-4 mt-4" + - past_movies.map do |movie| + a href=movie.url + figure + img class="rounded hover:opacity-80" src=movie.poster + figcaption= movie.title + hr - if text_posts.count > 0 div class="block grow bg-blue-100 dark:bg-blue-600 rounded px-4 py-2 mb-12" p class="text-sm mb-0" This week, years ago diff --git a/app/views/posts/show.rb b/app/views/posts/show.rb index 7be6aa3..6398fb2 100644 --- a/app/views/posts/show.rb +++ b/app/views/posts/show.rb @@ -4,7 +4,7 @@ module Adamantium module Views module Posts class Show < Adamantium::View - include Deps["repos.post_repo"] + include Deps["repos.post_repo", "repos.movie_repo"] expose :post do |slug:| Decorators::Posts::Decorator.new(post_repo.fetch!(slug)) @@ -17,6 +17,13 @@ module Adamantium posts.map { |p| Decorators::Posts::Decorator.new(p) } end + expose :past_movies do |post| + start_date = TimeMath.week.floor(post.published_at) + end_date = TimeMath.week.ceil(post.published_at) + movies = movie_repo.from_the_archives(start_date: start_date, end_date: end_date) + movies.map { |p| Decorators::Movies::Decorator.new(p) } + end + expose :text_posts do |past_posts| past_posts.reject(&:photos?) end diff --git a/config/providers/clients.rb b/config/providers/clients.rb index 561e0f7..334cbab 100644 --- a/config/providers/clients.rb +++ b/config/providers/clients.rb @@ -1,5 +1,6 @@ Hanami.app.register_provider :clients, namespace: true do start do register "mastodon", Adamantium::Client::Mastodon.new + register "omdb", Adamantium::Client::Omdb.new(api_key: target["settings"].omdb_api_key) end end diff --git a/config/settings.rb b/config/settings.rb index da19029..b5e667f 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -28,6 +28,8 @@ module Adamantium setting :lastfm_api_key, default: nil setting :lastfm_secret, default: nil + setting :omdb_api_key, default: nil + setting :from_email, default: nil setting :dayone_email, default: nil diff --git a/lib/adamantium/client/omdb.rb b/lib/adamantium/client/omdb.rb new file mode 100644 index 0000000..3d398aa --- /dev/null +++ b/lib/adamantium/client/omdb.rb @@ -0,0 +1,15 @@ +require "omdb/api" + +module Adamantium + module Client + class Omdb + def initialize(api_key:) + @client = ::Omdb::Api::Client.new(api_key: api_key) + end + + def call(imdb_id:) + @client.find_by_id(imdb_id) + end + end + end +end \ No newline at end of file diff --git a/public/assets/index.css b/public/assets/index.css index 726bd3b..0235b17 100644 --- a/public/assets/index.css +++ b/public/assets/index.css @@ -1172,6 +1172,10 @@ video { width: 1.5rem; } +.w-3 { + width: 0.75rem; +} + .max-w-prose { max-width: 65ch; } @@ -1442,6 +1446,10 @@ video { padding-top: 1rem; } +.pb-4 { + padding-bottom: 1rem; +} + .text-left { text-align: left; } @@ -1478,6 +1486,10 @@ video { font-size: 0.75rem; } +.text-2xl { + font-size: 1.563rem; +} + .font-bold { font-weight: 700; } diff --git a/slices/admin/repos/movie_repo.rb b/slices/admin/repos/movie_repo.rb index fc81dc1..599d287 100644 --- a/slices/admin/repos/movie_repo.rb +++ b/slices/admin/repos/movie_repo.rb @@ -7,10 +7,6 @@ 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