最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python統(tǒng)計節(jié)假日剩余天數(shù)的腳本

 更新時間:2022年02月15日 10:46:12   作者:wangmcn  
過完春節(jié),盼著下一個節(jié)日,那么如何判斷距離節(jié)假日還有多少天呢?今天小編給大家介紹使用python腳本來解決這個問題,對Python統(tǒng)計節(jié)假日倒計時腳本感興趣的朋友一起看看吧

1、前言

如何快速的想了解距離節(jié)假日還有多少天?

接下來使用Python腳本來解決這個問題。

2、倒計時腳本

腳本代碼:

#!/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": "清明節(jié)"}, # 距離清明
        {"v_": distance_5_1, "title": "勞動節(jié)"}, # 距離勞動
        {"v_": distance_5_5, "title": "端午節(jié)"}, # 距離端午
        {"v_": distance_8_15, "title": "中秋節(jié)"}, # 距離中秋
        {"v_": distance_10_1, "title": "國慶節(jié)"}, # 距離國慶
    ]
    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'\n\t\t {Fore.GREEN}{now_} {week_day_}')
    str_ = '''
         開始!
    '''
    print(f'{Fore.RED}{str_}')
    time_ = time_parse(today)
    for t_ in time_:
        print(f'\t\t {Fore.RED}距離{t_.get("title")}還有: {t_.get("v_")}天')
    tips_ = '''
         結(jié)束!
    print(f'{Fore.RED}{tips_}')
    print(f'\t\t{Fore.CYAN} 公眾號:AllTests軟件測試\n')
if __name__ == '__main__':
    countdown()

在PyCharm上執(zhí)行結(jié)果:

在終端上執(zhí)行結(jié)果:

到此這篇關(guān)于Python統(tǒng)計節(jié)假日剩余天數(shù)的腳本的文章就介紹到這了,更多相關(guān)Python統(tǒng)計節(jié)假日內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 用python畫一只可愛的皮卡丘實例

    用python畫一只可愛的皮卡丘實例

    今天小編就為大家分享一篇用python畫一只可愛的皮卡丘實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • Python中很常用的函數(shù)map()用法實例

    Python中很常用的函數(shù)map()用法實例

    這篇文章主要給大家介紹了關(guān)于Python中很常用的函數(shù)map()用法的相關(guān)資料,map()函數(shù)是Python的內(nèi)置函數(shù),會根據(jù)提供的函數(shù)參數(shù),對傳入的序列數(shù)據(jù)進行映射,需要的朋友可以參考下
    2023-10-10
  • Django Admin 實現(xiàn)外鍵過濾的方法

    Django Admin 實現(xiàn)外鍵過濾的方法

    下面小編就為大家?guī)硪黄狣jango Admin 實現(xiàn)外鍵過濾的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • Python PyMuPDF實現(xiàn)PDF與圖片和PPT相互轉(zhuǎn)換

    Python PyMuPDF實現(xiàn)PDF與圖片和PPT相互轉(zhuǎn)換

    能夠用來對PDF文檔進行操作的Python包有好幾個,如提取內(nèi)容的PdfPlumber、PDFMiner,可以用來對PDF文件進行修改操作的PyPDF2等等,如果只是需要簡單地對PDF文件實現(xiàn)合并、拆分、書簽操作,使用PyPDF2就足以滿足。但如果想對PDF文件進行一些底層操作,基本上只有PyMuPDF了
    2022-12-12
  • pytorch_detach 切斷網(wǎng)絡(luò)反傳方式

    pytorch_detach 切斷網(wǎng)絡(luò)反傳方式

    這篇文章主要介紹了pytorch_detach 切斷網(wǎng)絡(luò)反傳方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-05-05
  • Python和OpenCV庫實現(xiàn)識別人物出現(xiàn)并鎖定

    Python和OpenCV庫實現(xiàn)識別人物出現(xiàn)并鎖定

    本文主要介紹了Python和OpenCV庫實現(xiàn)識別人物出現(xiàn)并鎖定,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • Python讀取Excel批量寫入到PPT并生成詞卡

    Python讀取Excel批量寫入到PPT并生成詞卡

    這篇文章主要為大家詳細介紹了如何使用Python實現(xiàn)讀取Excel并批量寫入到PPT生成詞卡,文中的示例代碼講解詳細,有需要的小伙伴可以參考一下
    2024-12-12
  • Python?copy()與deepcopy()方法之間有什么區(qū)別

    Python?copy()與deepcopy()方法之間有什么區(qū)別

    這篇文章主要介紹了Python中的copy()和deepcopy(),下面詳細介紹該內(nèi)容并附上詳細代碼,需要的朋友可以參考一下文章的具體內(nèi)容,希望對你有所幫助
    2022-10-10
  • Python+SQLAlchemy輕松實現(xiàn)管理數(shù)據(jù)庫

    Python+SQLAlchemy輕松實現(xiàn)管理數(shù)據(jù)庫

    QLAlchemy是一個強大的ORM(對象關(guān)系映射)庫,它允許您通過Python代碼與關(guān)系型數(shù)據(jù)庫進行交互,本文我們將學(xué)習(xí)如何使用Python和SQLAlchemy庫來輕松管理數(shù)據(jù)庫,需要的可以參考下
    2023-05-05
  • Python中random函數(shù)的用法整理大全

    Python中random函數(shù)的用法整理大全

    random庫是使用隨機數(shù)的Python標準庫,random庫主要用于生成隨機數(shù),下面這篇文章主要給大家介紹了關(guān)于Python?random函數(shù)用法的相關(guān)資料,文中通過圖文以及實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-08-08

最新評論

启东市| 临沧市| 义马市| 湖州市| 临邑县| 玉环县| 玉屏| 衡阳市| 辽宁省| 耿马| 中江县| 霍林郭勒市| 油尖旺区| 阳朔县| 青州市| 瓮安县| 康平县| 宁国市| 新化县| 自贡市| 九龙坡区| 栾城县| 海盐县| 遂昌县| 万安县| 濮阳县| 京山县| 光山县| 永善县| 岚皋县| 江达县| 永平县| 连州市| 南召县| 西丰县| 繁峙县| 阿瓦提县| 外汇| 中超| 凌云县| 仙居县|