Skip to content

Commit

Permalink
load r/baseball game threads
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Hoffman <[email protected]>
  • Loading branch information
Fustrate committed Mar 20, 2024
1 parent e478ce8 commit 24f4c9e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def cli(*command, **kwargs)

every :day do
cli :game_threads, :load
cli :game_threads, :load_r_baseball
cli :game_threads, :load_r_albeast
cli :sync_moderators
end

Expand Down
9 changes: 9 additions & 0 deletions scripts/cli/flair.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# Copyright (c) Valencia Management Group
# All rights reserved.

require_relative 'subcommand'

class Flair < Subcommand
end
14 changes: 14 additions & 0 deletions scripts/cli/game_threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def load
puts "Added #{results[:created]}, Updated #{results[:updated]}"
end

desc 'load_r_baseball', ''
def load_r_baseball
require_relative '../load_baseball_game_threads'

BaseballGameThreadLoader.new.run
end

desc 'load_r_albeast', ''
def load_r_albeast
require_relative '../load_albeast_game_threads'

ALEastGameThreadLoader.new.run
end

desc 'load_postseason', ''
def load_postseason
require_relative '../load_postseason_game_threads'
Expand Down
2 changes: 0 additions & 2 deletions scripts/load_albeast_game_threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,3 @@ def post_at
@post_at ||= Baseballbot::Utility.adjust_time_proc(db.exec(POST_AT_QUERY)[0]['post_at'])
end
end

ALEastGameThreadLoader.new.run
28 changes: 28 additions & 0 deletions scripts/load_baseball_game_threads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require_relative 'game_thread_loader'

# /r/baseball is running a game thread for all games this season... for now.
class BaseballGameThreadLoader < GameThreadLoader
SUBREDDIT_ID = 15

POST_AT_QUERY = <<~SQL.freeze
SELECT options#>>'{game_threads,post_at}' AS post_at
FROM subreddits
WHERE id = #{SUBREDDIT_ID}
SQL

def initialize
super(date: Date.new(Date.today.year, Date.today.month, 1))
end

def add_game(game)
starts_at = Time.parse(game['gameDate']) + @utc_offset

insert_game(SUBREDDIT_ID, game, post_at.call(starts_at), starts_at)
end

def post_at
@post_at ||= Baseballbot::Utility.adjust_time_proc(db.exec(POST_AT_QUERY)[0]['post_at'])
end
end

0 comments on commit 24f4c9e

Please sign in to comment.