美文网首页
2022年节假日倒计时脚本

2022年节假日倒计时脚本

作者: aq_wzj | 来源:发表于2022-12-11 16:49 被阅读0次

脚本:

from datetime import datetime
import time
import os

today = datetime.now()

jieri_list = [
    {"name": "妇女节", "date": "2022-03-08 00:00:00"},
    {"name": "愚人节", "date": "2022-04-01 00:00:00"},
    {"name": "清明节", "date": "2022-04-03 00:00:00"},
    {"name": "五一节", "date": "2022-04-30 00:00:00"},
    {"name": "青年节", "date": "2022-05-04 00:00:00"},
    {"name": "母亲节", "date": "2022-05-08 00:00:00"},
    {"name": "儿童节", "date": "2022-06-01 00:00:00"},
    {"name": "端午节", "date": "2022-06-03 00:00:00"},
    {"name": "父亲节", "date": "2022-06-19 00:00:00"},
    {"name": "建党节", "date": "2022-07-01 00:00:00"},
    {"name": "火把节", "date": "2022-07-22 00:00:00"},
    {"name": "建军节", "date": "2022-08-01 00:00:00"},
    {"name": "七夕节", "date": "2022-08-04 00:00:00"},
    {"name": "中元节", "date": "2022-08-12 00:00:00"},
    {"name": "中秋节", "date": "2022-09-10 00:00:00"},
    {"name": "教师节", "date": "2022-09-10 00:00:00"},
    {"name": "国庆节", "date": "2022-10-01 00:00:00"},
    {"name": "重阳节", "date": "2022-10-04 00:00:00"},
    {"name": "万圣夜", "date": "2022-10-31 00:00:00"},
    {"name": "光棍节", "date": "2022-11-11 00:00:00"},
    {"name": "感恩节", "date": "2022-11-24 00:00:00"},
    {"name": "平安夜", "date": "2022-12-24 00:00:00"},
    {"name": "圣诞节", "date": "2022-12-25 00:00:00"},
    {"name": "腊八节", "date": "2022-12-30 00:00:00"},
    {"name": "元旦节", "date": "2023-01-01 00:00:00"},
    {"name": "除夕节", "date": "2023-01-21 00:00:00"},
]


def get_other_day(jieri):
    jieridata = datetime.strptime(jieri["date"], "%Y-%m-%d %H:%M:%S")

    if (jieridata - today).days < 0:
        if (today - jieridata).days == 0:
            return f"今天是 {jieri['name']} \n"
        return f"距离 {jieri['name']} 已过 {(today - jieridata).days}天\n"
    else:
        res = f"距离 {jieri['name']} 还有 "  # {(jieridata - today).days}天

        days = (jieridata - today).days
        times = f"{int((jieridata - today).seconds / 3600)}时{int(((jieridata - today).seconds % 3600) / 60)}分{int((jieridata - today).seconds % 60)}秒"

        if (jieridata - today).days == 0:
            res += times
        elif (jieridata - today).days == 1:
            res += f"{days}天 {times}"
        else:
            res += f"{days}天"
        return f"{res} \n"



def mo():
    global today
    xiaban = datetime.strptime("17:30:00", "%H:%M:%S")  # 下班
    today = datetime.now()
    while True:
        today = datetime.now()
        # {int((yr - today).seconds / 3600)}时{int(((yr - today).seconds % 3600) / 60)}分{int((yr - today).seconds % 60)}秒
        print(f"""\r======== 当前时间 {datetime.strftime(today, '%Y-%m-%d %H:%M:%S')}========
{"".join([get_other_day(i) for i in jieri_list])}

距离 下班 还有 {int((xiaban - today).seconds / 3600)}时{int(((xiaban - today).seconds % 3600) / 60)}分{int((xiaban - today).seconds % 60)}秒
""", end="")
        time.sleep(1)
        # os.system('cls')  用这个刷新屏幕会闪烁, 改用下面的不会
        print("\033[H\033[J", end="")


if __name__ == '__main__':
    mo()

运行截图


image.png

相关文章

  • python获取全年节假日

    工作时,偶尔需要获取全年节假日期,python脚本如下: 获取2020年全年节假日

  • 2022年节假日倒计时脚本

    脚本: 运行截图

  • 倒计时

    脚本把下面脚本保存到.bat文件中 倒计时效果倒计时(样例从60秒倒计时)

  • 【工作巴】值班

    2022年10月5日 周三 曲靖 晴 今日国庆节值班,我部门轮到一天。 感谢关心,全年节假日值班,我部门轮到...

  • 【说法】2019,人社部最新休假标准来了!

    近日,人力资源和社会保障部官网发布《我国法定年节假日等休假相关标准》,对包括休息日、法定年节假日、年休假、探亲假、...

  • 长假高速免费带来了啥!

    为了促进消费,最近今年节假日高速一直在免费。

  • you are what you say——蔡康永的说话之道

    “新年将至,祝你、、、、、、”“辞旧迎新、、、、、、”“包包,新年快乐!”“、、、、、、、” 每年节假日,我们的手...

  • 青年节假日

    今天,青年节假日啊。 我,在哪? 在学校~~~改作业!!! 办公室里,一片寂静。除了我和邻座的同事,没有其他人回来...

  • 假日倒计时

    昨天完成了两个重要任务: 1完成了给三年级家长的第一封信。按计划本应该是开学就要写好发出来的,但是一直心没有静下来...

  • 不放假的五四青年节,可以这样过,职场篇

    五四青年节虽说是一个节日,可是由于众所周知的原因,五四青年节没有被列为法定节假日,也就没有放假。虽然不放假,可以身...

网友评论

      本文标题:2022年节假日倒计时脚本

      本文链接:https://www.haomeiwen.com/subject/ipifqdtx.html