Last active
September 4, 2018 22:45
-
-
Save shinmiy/cc9555f67afd150ec99a9e00600926c2 to your computer and use it in GitHub Desktop.
日記のテンプレジェネレーター
This file contains hidden or 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
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こういうのができる
Week # 27 (2018/07/02 - 2018/07/07)
July 2018 #WeeklyRoundup
Topics
Photos