Skip to content

Instantly share code, notes, and snippets.

@betachelsea
Created May 22, 2024 15:05
Show Gist options
  • Save betachelsea/41d9c31198f7338345a4e3d51edfa4b4 to your computer and use it in GitHub Desktop.
Save betachelsea/41d9c31198f7338345a4e3d51edfa4b4 to your computer and use it in GitHub Desktop.
Rubyさまの言うとおりscript
require "csv"
WANT_TO_DO_CSV = "./want_to_do.csv" # やりたいことリストを準備しておく
HISTORY_CSV = "./history.csv"
puts "Eeny, meeny, miny, moe"
old_history = CSV.read(HISTORY_CSV, headers: true)
@today_pickup_todo = nil
def pickup_todo
@today_pickup_todo = [Date.today.to_s, CSV.read(WANT_TO_DO_CSV).flatten.sample]
end
new_history = CSV.open(HISTORY_CSV, 'w')
new_history.puts ["date", "what_todo"]
old_history.each do |log|
if log["date"] == Date.today.to_s
new_history.puts pickup_todo
else
new_history.puts log
end
end
new_history.puts pickup_todo if @today_pickup_todo.nil?
new_history.close
puts "Your todo: #{@today_pickup_todo[1]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment