Skip to content

Instantly share code, notes, and snippets.

@shinmiy
Last active September 4, 2018 22:45
Show Gist options
  • Save shinmiy/cc9555f67afd150ec99a9e00600926c2 to your computer and use it in GitHub Desktop.
Save shinmiy/cc9555f67afd150ec99a9e00600926c2 to your computer and use it in GitHub Desktop.
日記のテンプレジェネレーター
#!/usr/bin/ruby
require "date"
class Date
def this_sunday # 次の日曜日 or 日曜日なら当日
self + (7 - self.wday) % 7
end
def prev_monday # 直前の月曜日 or 月曜日なら当日
self + (7 - self.wday) % 7 - 6
end
end
# 日付を引数を受けて、パースできそうなら採用する
begin
today = Date.parse(ARGV[0])
rescue
today = Date.today
end
# ヘッダー
week_start = today.prev_monday
week_end = today.this_sunday
print "# Week # #{today.cweek} "
print "(#{week_start.strftime("%Y/%m/%d")} - #{week_end.strftime("%Y/%m/%d")})\n"
print "#{week_start.strftime("%B %Y")} #WeeklyRoundup\n\n"
# カレンダー
print "|月|火|水|木|金|土|日|\n"
print "|:--:|:--:|:--:|:--:|:--:|:--:|:--:|\n"
first_day = Date.new(today.year, today.month, 1)
last_day = Date.new(today.year, today.month, -1)
start_day = first_day.prev_monday # この日から
end_day = last_day.this_sunday # この日までを表示する
diff = (end_day - start_day).to_i
(0..diff).map {|i| start_day + i}.each {|day|
print "|"
print "<font color=\"Blue\">" if day.saturday?
print "<font color=\"Crimson\">" if day.sunday?
print "<b>" if day.cweek == today.cweek
print day.day
print "</b>" if day.cweek == today.cweek
print "</font>" if day.saturday? || day.sunday?
print "|\n" if day.sunday?
}
print "\n"
# 残り
print "## Topics\n\n"
print "## Photos\n"
@shinmiy
Copy link
Author

shinmiy commented Jul 2, 2018

こういうのができる

Week # 27 (2018/07/02 - 2018/07/07)

July 2018 #WeeklyRoundup

2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

Topics

Photos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment