Created
May 22, 2024 15:05
-
-
Save betachelsea/41d9c31198f7338345a4e3d51edfa4b4 to your computer and use it in GitHub Desktop.
Rubyさまの言うとおりscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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