Skip to content

Instantly share code, notes, and snippets.

@chun37
Created July 17, 2017 17:55
Show Gist options
  • Save chun37/7faf9b57fa8f4d3e90815a7f1d2dfde8 to your computer and use it in GitHub Desktop.
Save chun37/7faf9b57fa8f4d3e90815a7f1d2dfde8 to your computer and use it in GitHub Desktop.
年月日から何月の第何何曜日か、祝日であれば祝日名をプリント
# -*- coding: utf-8 -*-
import datetime
import sys
try:
g, y, m, d = sys.argv
except:
exit()
try:
t = datetime.date(int(y), int(m), int(d))
try:
print {"1, 1": u"元日", "4, 29": u"昭和の日", "5, 3": u"憲法記念日", "5, 4": u"みどりの日", "5, 5": u"こどもの日", "8, 11": u"山の日", "11, 3": u"文化の日", "11, 23": u"勤労感謝の日", "12, 23": u"天皇誕生日"}[str([int(m), int(d)])[1:-1]]
except:
pass
try:
print {"1, 2, 0": u"成人の日", "7, 3, 0": u"海の日", "9, 3, 0": u"敬老の日", "10, 2, 0": u"体育の日"}[str([int(m), (t.day - 1) // 7 + 1, t.weekday()])[1:-1]]
except:
pass
try:
print {'3, {}'.format(int(20.8431 + 0.242194 * (int(y) - 1980) - int((int(y) - 1980) / 4))): u'春分の日', '9, {}'.format(int(23.2488 + 0.242194 * (int(y) - 1980) - int((int(y) - 1980) / 4))): u'秋分の日'}[str([int(m), int(d)])[1:-1]]
except:
pass
print u"%s月の第%s週%s曜日" % (int(m), (t.day - 1) // 7 + 1, [u"月", u"火", u"水", u"木", u"金", u"土", u"日"][t.weekday()])
except:
exit()
@neet
Copy link

neet commented Jul 17, 2017

From line 8:

try:
    
    t = datetime.date(int(y), int(m), int(d))

    try:
        print {"1, 1": u"元日", "4, 29": u"昭和の日", "5, 3": u"憲法記念日", "5, 4": u"みどりの日", "5, 5": u"こどもの日", "8, 11": u"山の日", "11, 3": u"文化の日", "11, 23": u"勤労感謝の日", "12, 23": u"天皇誕生日"}[str([int(m), int(d)])[1:-1]]
        print {"1, 2, 0": u"成人の日", "7, 3, 0": u"海の日", "9, 3, 0": u"敬老の日", "10, 2, 0": u"体育の日"}[str([int(m), (t.day - 1) // 7 + 1, t.weekday()])[1:-1]]
        print {'3, {}'.format(int(20.8431 + 0.242194 * (int(y) - 1980) - int((int(y) - 1980) / 4))): u'春分の日', '9, {}'.format(int(23.2488 + 0.242194 * (int(y) - 1980) - int((int(y) - 1980) / 4))): u'秋分の日'}[str([int(m), int(d)])[1:-1]]
    except:
        pass

    print u"%s月の第%s週%s曜日" % (int(m), (t.day - 1) // 7 + 1, [u"月", u"火", u"水", u"木", u"金", u"土", u"日"][t.weekday()])
    
except:
    exit()

このほうがよくね

@chun37
Copy link
Author

chun37 commented Jul 17, 2017

それすると
2行目と3行目が絶対にprintされない

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