From def06e17e8595523417d4f86ee7326a343d222af Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Fri, 26 Jan 2024 10:56:44 +1100 Subject: [PATCH] Add ratings to movies --- Rakefile | 17 ++++++++++++++++- app/templates/movies/index.html.slim | 6 ++++++ .../20240125232452_add_rating_to_movies.rb | 9 +++++++++ slices/admin/commands/movies/create.rb | 6 +++++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20240125232452_add_rating_to_movies.rb diff --git a/Rakefile b/Rakefile index 4d68c6f..f3ea50c 100644 --- a/Rakefile +++ b/Rakefile @@ -25,11 +25,26 @@ namespace :blog do title: title, year: activity.year, url: activity.film_link, - watched_at: activity.watched_at + watched_at: activity.watched_at, + rating: (activity.score / 2.0) }) end end + task load_twitter_archive: ["blog:load_environment"] do + require "hanami/prepare" + + repo = Micropub::Container["repos.post_repo"] + file = "tmp/tweets.json" + tweets = JSON.parse(File.read(file)) + tweets.each do |tweet| + next if tweet["tweet"]["full_text"].start_with? "@" + tweet["tweet"]["full_text"] = tweet["tweet"]["full_text"].gsub(/(#{URI::DEFAULT_PARSER.make_regexp})/, "#{$1}") + + repo.create({slug: tweet["tweet"]["id"], content: tweet["tweet"]["full_text"], published_at: tweet["tweet"]["created_at"], category: [], post_type: "post", syndication_sources: {twitter: "https://twitter.com/nitza/status/#{tweet["tweet"]["id"]}"}}) + end + end + task scrobble_podcasts: ["blog:load_environment"] do require "hanami/prepare" diff --git a/app/templates/movies/index.html.slim b/app/templates/movies/index.html.slim index b558e7c..24d632b 100644 --- a/app/templates/movies/index.html.slim +++ b/app/templates/movies/index.html.slim @@ -9,6 +9,7 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark: tr td Title td Year + td Rating - movies.each do |movie| tr td @@ -16,5 +17,10 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark: = movie.title td = movie.year + td class="min-w-32" + - if movie.rating > 0 + == "#{'🌕' * movie.rating.floor}#{'🌗' * (movie.rating % movie.rating.floor).ceil}" + - else + == " " div class="max-w-screen-md mx-auto border-t border-solid border-gray-200 dark:border-gray-600" diff --git a/db/migrate/20240125232452_add_rating_to_movies.rb b/db/migrate/20240125232452_add_rating_to_movies.rb new file mode 100644 index 0000000..d9c73b0 --- /dev/null +++ b/db/migrate/20240125232452_add_rating_to_movies.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +ROM::SQL.migration do + change do + alter_table(:movies) do + add_column :rating, :float, default: 0.0 + end + end +end diff --git a/slices/admin/commands/movies/create.rb b/slices/admin/commands/movies/create.rb index f217048..f76b29d 100644 --- a/slices/admin/commands/movies/create.rb +++ b/slices/admin/commands/movies/create.rb @@ -9,7 +9,11 @@ module Admin def call(movie) repo = Container["repos.movie_repo"] - return if repo.by_title_and_year(title: movie[:title], year: movie[:year]) + db_movie = repo.by_title_and_year(title: movie[:title], year: movie[:year]) + if db_movie + repo.update(db_movie.id, rating: movie[:rating]) + return + end page = Down.download(movie[:url]) match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)