摸鱼办--python版

引言

最早在群里,后来在x社区看到过,感觉挺有意思的,所以用python写了个简易版。

代码

import datetime
import math
import os

import zhdate
from zhdate import ZhDate

now = datetime.datetime.now()
周末 = 5 - now.weekday()
劳动 = math.ceil((datetime.datetime(now.year, 5, 1).timestamp() - now.timestamp()) / 86400)
中秋 = ZhDate(now.year, 8, 15).to_datetime().toordinal() - now.toordinal()
国庆 = math.ceil((datetime.datetime(now.year, 10, 1).timestamp() - now.timestamp()) / 86400)
元旦 = math.ceil((datetime.datetime(now.year + 1, 1, 1).timestamp() - now.timestamp()) / 86400)

strBase = f"{now.year}年{now.month}月{now.day}日,{zhdate.ZhDate.from_datetime(now)},大家"
if now.hour < 9:
    strBase += """早上"""
elif now.hour < 12:
    strBase += """上午"""
elif now.hour < 13:
    strBase += """中午"""
elif now.hour < 18:
    strBase += """下午"""
elif now.hour < 24:
    strBase += """晚上"""

strBase += f"""好,工作再累,一定不要忘记摸鱼哦!有事没事起身去茶水间,去厕所,去廊道走走。别老在工位上坐着,上班是帮老板赚钱,摸鱼是赚老板的钱!"""
print(strBase)
print(f"""距离周六还有""", 周末, "天")
print(f"""劳动节已经过了 {abs(劳动)} 天""" if 劳动 < 0 else f"距离劳动节还有{劳动} 天")
print(f"""中秋已经过了 {abs(中秋)} 天""" if 中秋 < 0 else f"距离中秋节还有 {中秋} 天")
print(f"""国庆已经过了 {abs(国庆)} 天""" if 国庆 < 0 else f"距离国庆节还有 {国庆} 天")
print(f"""元旦已经过了 {abs(元旦)} 天""" if 元旦 < 0 else f"距离元旦还有 {元旦} 天")

os.system("pause")  # 此时可以用鼠标复制,发动态喽。

效果

image.png

评论 0

还没有评论,来说点什么吧。

提交后需要审核才会公开。