Show movies watched on weekly posts

This commit is contained in:
2023-05-13 12:45:31 +10:00
parent f613717852
commit bcaab0754a
12 changed files with 101 additions and 28 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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