nikki.rb
日記のテンプレートを Ruby で雑に生成している。 code:nikki.rb
require "date"
require "json"
require "open-uri"
require "uri"
arg = ARGV.shift
date = arg ? Date.parse(arg) : Date.today
next_title = (date + 1).strftime("%Y-%m-%d %a : (書きかけ)")
title = date.strftime("%Y-%m-%d %a : (書きかけ)")
year_month_day = date.strftime("%Y-%m-%d")
year = date.strftime("%Y")
year_month = date.strftime("%Y年%m月")
month_day = date.strftime("%m月%d日")
week_number = "WN" + date.strftime("%V")
june2x = date.strftime("%m%d").start_with?("062") ? "\njune2X 週間。\n" : nil good_meat = date.strftime("%m%d") == "1129" ? "いい肉の日\n" : nil headers =
join("\n")
prev_title =
JSON.parse(URI.open("#{base_url}#{date - 1}").read).
dig("relatedPages", "links1hop").
find { |page| page.dig("title").match(Regexp.compile((date - 1).strftime("%Y-%m-%d %a : "))) }.
dig("title")
n_years_ago =
JSON.parse(URI.open("#{base_url}#{URI.encode_www_form_component(month_day)}").read).
dig("relatedPages", "links1hop").
select { |page| page.dig("title").match(Regexp.compile(date.strftime("\\d{4}-%m-%d \\w{3} : "))) }.
reject { |page| page.dig("title").include?("書きかけ") }.
sort_by { |page| page.dig("title") }.
reverse.
map { |page| t = page.dig("title"); " %s / %s" % [t0..9, t] }. join("\n")
puts <<~STRING
今日の n 年前
ナビ
STRING