<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
如何快速的想了解距離節假日還有多少天?
接下來使用Python指令碼來解決這個問題。
指令碼程式碼:
#!/usr/bin/env python # -*- coding: utf-8 -*- from colorama import init, Fore from zhdate import ZhDate import datetime def get_week_day(date): week_day_dict = { 0: '星期一', 1: '星期二', 2: '星期三', 3: '星期四', 4: '星期五', 5: '星期六', 6: '星期天', } day = date.weekday() return week_day_dict[day] def time_parse(today): distance_year = (datetime.datetime.strptime(f"{today.year}-01-01", "%Y-%m-%d").date() - today).days distance_year = distance_year if distance_year > 0 else ( datetime.datetime.strptime(f"{today.year + 1}-01-01", "%Y-%m-%d").date() - today).days distance_big_year = (ZhDate(today.year, 1, 1).to_datetime().date() - today).days distance_big_year = distance_big_year if distance_big_year > 0 else ( ZhDate(today.year + 1, 1, 1).to_datetime().date() - today).days distance_4_5 = (datetime.datetime.strptime(f"{today.year}-04-05", "%Y-%m-%d").date() - today).days distance_4_5 = distance_4_5 if distance_4_5 > 0 else ( datetime.datetime.strptime(f"{today.year + 1}-04-05", "%Y-%m-%d").date() - today).days distance_5_1 = (datetime.datetime.strptime(f"{today.year}-05-01", "%Y-%m-%d").date() - today).days distance_5_1 = distance_5_1 if distance_5_1 > 0 else ( datetime.datetime.strptime(f"{today.year + 1}-05-01", "%Y-%m-%d").date() - today).days distance_5_5 = (ZhDate(today.year, 5, 5).to_datetime().date() - today).days distance_5_5 = distance_5_5 if distance_5_5 > 0 else ( ZhDate(today.year + 1, 5, 5).to_datetime().date() - today).days distance_8_15 = (ZhDate(today.year, 8, 15).to_datetime().date() - today).days distance_8_15 = distance_8_15 if distance_8_15 > 0 else ( ZhDate(today.year + 1, 8, 15).to_datetime().date() - today).days distance_10_1 = (datetime.datetime.strptime(f"{today.year}-10-01", "%Y-%m-%d").date() - today).days distance_10_1 = distance_10_1 if distance_10_1 > 0 else ( datetime.datetime.strptime(f"{today.year + 1}-10-01", "%Y-%m-%d").date() - today).days # print("距離週末: ", 5 - today.weekday()) # print("距離元旦: ", distance_year) # print("距離大年: ", distance_big_year) # print("距離清明: ", distance_4_5) # print("距離勞動: ", distance_5_1) # print("距離端午: ", distance_5_5) # print("距離中秋: ", distance_8_15) # print("距離國慶: ", distance_10_1) time_ = [ {"v_": 5 - 1 - today.weekday(), "title": "週末"}, # 距離週末 {"v_": distance_year, "title": "元旦"}, # 距離元旦 {"v_": distance_big_year, "title": "過年"}, # 距離過年 {"v_": distance_4_5, "title": "清明節"}, # 距離清明 {"v_": distance_5_1, "title": "勞動節"}, # 距離勞動 {"v_": distance_5_5, "title": "端午節"}, # 距離端午 {"v_": distance_8_15, "title": "中秋節"}, # 距離中秋 {"v_": distance_10_1, "title": "國慶節"}, # 距離國慶 ] time_ = sorted(time_, key=lambda x: x['v_'], reverse=False) return time_ def countdown(): init(autoreset=True) today = datetime.date.today() now_ = f"{today.year}年{today.month}月{today.day}日" week_day_ = get_week_day(today) print(f'ntt {Fore.GREEN}{now_} {week_day_}') str_ = ''' 開始! ''' print(f'{Fore.RED}{str_}') time_ = time_parse(today) for t_ in time_: print(f'tt {Fore.RED}距離{t_.get("title")}還有: {t_.get("v_")}天') tips_ = ''' 結束! print(f'{Fore.RED}{tips_}') print(f'tt{Fore.CYAN} 公眾號:AllTests軟體測試n') if __name__ == '__main__': countdown()
在PyCharm上執行結果:
在終端上執行結果:
到此這篇關於Python統計節假日剩餘天數的指令碼的文章就介紹到這了,更多相關Python統計節假日內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45