LoginSignup
0
2

[Python] 祝日を判定する

Last updated at Posted at 2022-11-09

0.初めに

国内株などに投資をしていると平日だけ実行したいプログラムが思い浮かぶ。
Windows10 のタスクスケジューラは祝日に実行しない設定が存在しない。
そこで祝日のみをピンポイントで弾く必要性を感じた。

1.jpholidayをインストールする

コマンドプロンプトで
pip install jpholiday
を入力

2.サンプルプログラム

holiday.pyは祝日のとき終了するプログラム
exit()の下に(インデントを戻して)実施したいプログラムを記述すればよい

holiday.py
import datetime
import jpholiday

if jpholiday.is_holiday(datetime.date.today()):
    print("Today is a holiday, so this program will not work.")
    exit()

参照先
https://github.com/Lalcs/jpholiday

3.問題点

年末年始が対応してませんね。
金融機関は12/31,1/2,1/3を追加
役所はさらに12/29,12/30を追加
しなければならない。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2