From cbdc61c359f875019cd9088317368d3349911e8b Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Mon, 1 Apr 2024 19:13:18 +1100 Subject: [PATCH] Add more endpoints for now page --- Gemfile | 27 ++++++++++--------- Gemfile.lock | 21 +++++---------- Rakefile | 2 +- config/app.rb | 1 + config/settings.rb | 4 +++ slices/main/actions/past_week/index.rb | 15 +++++++++++ .../actions/recently_played_games/index.rb | 15 +++++++++++ slices/main/config/routes.rb | 2 ++ slices/main/queries/posts/recent_games.rb | 16 +++++++++++ .../main/templates/past_week/index.html.slim | 3 +++ .../recently_played_games/index.html.slim | 8 ++++++ slices/main/views/past_week/index.rb | 17 ++++++++++++ .../main/views/recently_played_games/index.rb | 25 +++++++++++++++++ 13 files changed, 128 insertions(+), 28 deletions(-) create mode 100644 slices/main/actions/past_week/index.rb create mode 100644 slices/main/actions/recently_played_games/index.rb create mode 100644 slices/main/queries/posts/recent_games.rb create mode 100644 slices/main/templates/past_week/index.html.slim create mode 100644 slices/main/templates/recently_played_games/index.html.slim create mode 100644 slices/main/views/past_week/index.rb create mode 100644 slices/main/views/recently_played_games/index.rb diff --git a/Gemfile b/Gemfile index 476d36e..1f0cc71 100644 --- a/Gemfile +++ b/Gemfile @@ -14,9 +14,10 @@ gem "hanami-view", "2.1.0" gem "csv" gem "rom-sql" gem "pg" -gem "scraperd", github: "dNitza/scraperd", branch: "master" gem "dotenv" +gem "whenever", require: false +gem "warning" gem "dry-types" gem "dry-matcher" @@ -25,11 +26,13 @@ gem "puma" gem "rake" gem "slim" gem "builder" -gem "georuby" gem "gpx" + +gem "redis" + +gem "georuby" gem "gnuplot" gem "matrix" -gem "redis" gem "rack-session" gem "rack-rewrite" @@ -42,27 +45,25 @@ gem "redcarpet" gem "reverse_markdown" gem "rexml" gem "babosa" -gem "bskyrb" -gem "ogpr" gem "ruby-filemagic", git: "https://github.com/dnitza/ruby-filemagic", branch: "master" -gem "mail_room", github: "dNitza/mail_room", branch: "master" gem "charlock_holmes" gem "sanitize" gem "time_math2", require: "time_math" gem "jwt" -gem "lastfm", "~> 1.27" gem "mail" gem "que" -gem "unicode-emoji" gem "connection_pool" -gem "omdb-api", "1.4.3", require: false gem "image_processing", "~> 1.0" -gem "onnxruntime" gem "mini_magick" +gem "unicode-emoji" -gem "whenever", require: false - -gem "warning" +gem "mail_room", github: "dNitza/mail_room", branch: "master" +gem "scraperd", github: "dNitza/scraperd", branch: "master" +gem "bskyrb" +gem "ogpr" +gem "omdb-api", "1.4.3", require: false +gem "lastfm", "~> 1.27" +gem "steam-api" group :cli, :development do gem "irb" diff --git a/Gemfile.lock b/Gemfile.lock index dd98747..918c6c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,10 +158,9 @@ GEM ed25519 (1.3.0) faker (3.3.0) i18n (>= 1.8.11, < 2) - faraday (2.9.0) - faraday-net_http (>= 2.0, < 3.2) - faraday-net_http (3.1.0) - net-http + faraday (1.2.0) + multipart-post (>= 1.2, < 3) + ruby2_keywords ffi (1.16.3) formatador (1.1.0) georuby (2.5.2) @@ -280,6 +279,7 @@ GEM mini_mime (1.1.5) minitest (5.22.3) multi_xml (0.6.0) + multipart-post (2.4.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mustermann-contrib (3.0.0) @@ -287,8 +287,6 @@ GEM mustermann (= 3.0.0) mutex_m (0.2.0) nenv (0.3.0) - net-http (0.4.1) - uri net-imap (0.4.10) date net-protocol @@ -327,12 +325,6 @@ GEM omdb-api (1.4.3) activesupport httparty - onnxruntime (0.9.0-arm64-darwin) - ffi - onnxruntime (0.9.0-x86_64-darwin) - ffi - onnxruntime (0.9.0-x86_64-linux) - ffi parallel (1.24.0) parser (3.3.0.5) ast (~> 2.4.1) @@ -479,6 +471,8 @@ GEM rubocop-performance (~> 1.20.2) standardrb (1.0.1) standard + steam-api (1.2.0) + faraday (~> 1.0) stringio (3.1.0) temple (0.10.3) thor (1.3.1) @@ -493,7 +487,6 @@ GEM unicode-emoji (3.4.0) unicode-version (~> 1.0) unicode-version (1.4.0) - uri (0.13.0) vernier (0.6.0) version_gem (1.1.4) warning (1.3.0) @@ -556,7 +549,6 @@ DEPENDENCIES mini_magick ogpr omdb-api (= 1.4.3) - onnxruntime pg puma que @@ -578,6 +570,7 @@ DEPENDENCIES scraperd! slim standardrb + steam-api time_math2 timecop unicode-emoji diff --git a/Rakefile b/Rakefile index 7f8cb75..4aca592 100644 --- a/Rakefile +++ b/Rakefile @@ -100,7 +100,7 @@ end namespace :tailwind do task :watch do - system("npx tailwindcss -i ./slices/main/assets/css/app.css -o ./slices/main/assets/builds/app.css --watch") + system("npx tailwindcss -i ./slices/main/assets/css/app.css -o ./public/assets/main/app.css --watch") end task :build do diff --git a/config/app.rb b/config/app.rb index 3e05a46..14dcd5e 100644 --- a/config/app.rb +++ b/config/app.rb @@ -26,6 +26,7 @@ module Adamantium "clients.omdb", "clients.blue_sky", "clients.mastodon", + "clients.steam", "geo.gpx_parser", "param_parser.micropub_post", "param_parser.webmention", diff --git a/config/settings.rb b/config/settings.rb index d105dfc..aa167be 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -76,5 +76,9 @@ module Adamantium setting :raise_exceptions, default: true setting :gist_client_token, default: nil + + setting :cache_pages, default: true + setting :steam_api_key, default: nil + setting :steam_user_id, default: nil end end diff --git a/slices/main/actions/past_week/index.rb b/slices/main/actions/past_week/index.rb new file mode 100644 index 0000000..a9a9832 --- /dev/null +++ b/slices/main/actions/past_week/index.rb @@ -0,0 +1,15 @@ +require "time_math" + +module Main + module Actions + module PastWeek + class Index < Action + include Deps["views.past_week.index"] + + def handle(req, res) + res.body = cache(key: "past_week", content_proc: -> { index.call.to_str }) + end + end + end + end +end diff --git a/slices/main/actions/recently_played_games/index.rb b/slices/main/actions/recently_played_games/index.rb new file mode 100644 index 0000000..cb1b916 --- /dev/null +++ b/slices/main/actions/recently_played_games/index.rb @@ -0,0 +1,15 @@ +require "time_math" + +module Main + module Actions + module RecentlyPlayedGames + class Index < Action + include Deps["views.recently_played_games.index"] + + def handle(req, res) + res.body = cache(key: "recently_played_games", content_proc: -> { index.call.to_str }) + end + end + end + end +end diff --git a/slices/main/config/routes.rb b/slices/main/config/routes.rb index 6309d7d..289aa3c 100644 --- a/slices/main/config/routes.rb +++ b/slices/main/config/routes.rb @@ -38,6 +38,8 @@ module Main get "/blogroll/opml", to: "blogroll.opml" get "/recently_played", to: "recently_played.index" + get "/recently_played_games", to: "recently_played_games.index" + get "/past_week", to: "past_week.index" get "/:slug", to: "pages.show" diff --git a/slices/main/queries/posts/recent_games.rb b/slices/main/queries/posts/recent_games.rb new file mode 100644 index 0000000..40b3872 --- /dev/null +++ b/slices/main/queries/posts/recent_games.rb @@ -0,0 +1,16 @@ +require "steam-api" + +module Main + module Queries + module Posts + class RecentGames + include Deps["settings"] + + def call + Steam.apikey = settings.steam_api_key + Steam::Player.recently_played_games(settings.steam_user_id).fetch("games", []).take(2) + end + end + end + end +end diff --git a/slices/main/templates/past_week/index.html.slim b/slices/main/templates/past_week/index.html.slim new file mode 100644 index 0000000..3c79473 --- /dev/null +++ b/slices/main/templates/past_week/index.html.slim @@ -0,0 +1,3 @@ +div class="bg-lime-100 rounded dark:bg-lime-900 dark:text-gray-100 content-justify hover:bg-lime-200 hover:dark:bg-lime-800 decoration-wavy rounded py-1.5 px-2" + = "Latest week post: " + a href="#{past_week.permalink}" #{past_week.name} \ No newline at end of file diff --git a/slices/main/templates/recently_played_games/index.html.slim b/slices/main/templates/recently_played_games/index.html.slim new file mode 100644 index 0000000..4334a1a --- /dev/null +++ b/slices/main/templates/recently_played_games/index.html.slim @@ -0,0 +1,8 @@ +table + - recently_played_games.each do |game| + tr + td + = game[:name] + + td + = "(#{game[:playtime_forever]}hrs)" \ No newline at end of file diff --git a/slices/main/views/past_week/index.rb b/slices/main/views/past_week/index.rb new file mode 100644 index 0000000..3644f18 --- /dev/null +++ b/slices/main/views/past_week/index.rb @@ -0,0 +1,17 @@ +module Main + module Views + module PastWeek + class Index < Main::View + config.layout = false + + include Deps["repos.post_repo"] + + expose :past_week do + post_repo.week_posts(limit: 1).to_a.map do |post| + Decorators::Posts::Decorator.new(post) + end.first + end + end + end + end +end diff --git a/slices/main/views/recently_played_games/index.rb b/slices/main/views/recently_played_games/index.rb new file mode 100644 index 0000000..8b8e799 --- /dev/null +++ b/slices/main/views/recently_played_games/index.rb @@ -0,0 +1,25 @@ +module Main + module Views + module RecentlyPlayedGames + class Index < Main::View + config.layout = false + + include Deps["queries.posts.recent_games"] + + expose :recently_played_games do |recently_played_result| + # raise recently_played_result["data"].inspect + recently_played_result.map do |game| + { + name: game["name"], + playtime_forever: game["playtime_forever"].to_i / 60, + } + end + end + + private_expose :recently_played_result do + recent_games.call + end + end + end + end +end