Add ratings to movies

This commit is contained in:
2024-01-26 10:56:44 +11:00
parent 62f3d1b800
commit def06e17e8
4 changed files with 36 additions and 2 deletions

View File

@@ -25,11 +25,26 @@ namespace :blog do
title: title, title: title,
year: activity.year, year: activity.year,
url: activity.film_link, url: activity.film_link,
watched_at: activity.watched_at watched_at: activity.watched_at,
rating: (activity.score / 2.0)
}) })
end end
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})/, "<a href='#{$1}'>#{$1}</a>")
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 task scrobble_podcasts: ["blog:load_environment"] do
require "hanami/prepare" require "hanami/prepare"

View File

@@ -9,6 +9,7 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
tr tr
td Title td Title
td Year td Year
td Rating
- movies.each do |movie| - movies.each do |movie|
tr tr
td td
@@ -16,5 +17,10 @@ div class="mb-12 prose dark:prose-invert max-w-prose mx-auto text-gray-800 dark:
= movie.title = movie.title
td td
= movie.year = movie.year
td class="min-w-32"
- if movie.rating > 0
== "#{'🌕' * movie.rating.floor}#{'🌗' * (movie.rating % movie.rating.floor).ceil}"
- else
== "&nbsp;"
div class="max-w-screen-md mx-auto border-t border-solid border-gray-200 dark:border-gray-600" div class="max-w-screen-md mx-auto border-t border-solid border-gray-200 dark:border-gray-600"

View File

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

View File

@@ -9,7 +9,11 @@ module Admin
def call(movie) def call(movie)
repo = Container["repos.movie_repo"] 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]) page = Down.download(movie[:url])
match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/) match = page.read.match(/href=".+title\/(tt\d+)\/maindetails"/)