お休みまであと何日?Python編
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[今さらPython]]
Pythonのライブラリ「jpholiday」を使うと祝日を判定できるけ...
対処方法は色々あるけど、まずは無難なところから。
オブジェクトについては、八割くらいは前やった休日判定の流...
* コード [#q752209c]
import datetime
import jpholiday
import os
class Hol():
def __init__(self,today):
self.today = today
self.yos = ["月","火","水","木","金","土","日"]
#self.handan(self.today)
self.holiday = None
self.answer = 0
self.days()
def handan(self,today):
self.name = jpholiday.is_holiday_name(today)
if(self.name != None):
self.holiday = self.name
elif(self.holiday9(self.today) != None):
self.holiday = "XHOLIDAY"
else:
self.yobi = self.yos[self.today.weekday()]
self.name = self.yobi + "曜日"
if(self.today.weekday() > 4):
self.holiday = self.name
def days(self):
self.answer = 0
if(jpholiday.is_holiday_name(self.today) == None):
if(self.holiday9(self.today) == None):
while 1:
self.answer = self.answer + 1
self.today = self.today + datetime.ti...
self.handan(self.today)
if(self.holiday != None):
break
def holiday9(self,today):
re1 = None
csv_holiday = os.environ["HOME"] + "/bin/holiday_...
s = ""
now = today.strftime("%Y%m%d\n") # rstrip()が本道...
with open(csv_holiday) as f:
for s_line in f:
if(now == s_line):
re1 = "HOLIDAY"
break
return(re1)
print(Hol(datetime.datetime.now()).answer)
これを実行すると、お休みまであと何日かと数字で返す……と思...
* 内容の説明 [#na36a296]
オブジェクトを作ると、.answerに休日までの日数が入るの。
判定材料はjphlidayの出力、土日かどうか、そして ユーザホー...
あとは好きにしてね。
終了行:
[[今さらPython]]
Pythonのライブラリ「jpholiday」を使うと祝日を判定できるけ...
対処方法は色々あるけど、まずは無難なところから。
オブジェクトについては、八割くらいは前やった休日判定の流...
* コード [#q752209c]
import datetime
import jpholiday
import os
class Hol():
def __init__(self,today):
self.today = today
self.yos = ["月","火","水","木","金","土","日"]
#self.handan(self.today)
self.holiday = None
self.answer = 0
self.days()
def handan(self,today):
self.name = jpholiday.is_holiday_name(today)
if(self.name != None):
self.holiday = self.name
elif(self.holiday9(self.today) != None):
self.holiday = "XHOLIDAY"
else:
self.yobi = self.yos[self.today.weekday()]
self.name = self.yobi + "曜日"
if(self.today.weekday() > 4):
self.holiday = self.name
def days(self):
self.answer = 0
if(jpholiday.is_holiday_name(self.today) == None):
if(self.holiday9(self.today) == None):
while 1:
self.answer = self.answer + 1
self.today = self.today + datetime.ti...
self.handan(self.today)
if(self.holiday != None):
break
def holiday9(self,today):
re1 = None
csv_holiday = os.environ["HOME"] + "/bin/holiday_...
s = ""
now = today.strftime("%Y%m%d\n") # rstrip()が本道...
with open(csv_holiday) as f:
for s_line in f:
if(now == s_line):
re1 = "HOLIDAY"
break
return(re1)
print(Hol(datetime.datetime.now()).answer)
これを実行すると、お休みまであと何日かと数字で返す……と思...
* 内容の説明 [#na36a296]
オブジェクトを作ると、.answerに休日までの日数が入るの。
判定材料はjphlidayの出力、土日かどうか、そして ユーザホー...
あとは好きにしてね。
ページ名: