退休计算器,贴心(定时推送,每日提醒)
本帖最后由 q3125418 于 2024-7-26 11:39 编辑设置退休时间:retirement_age = 65 (啊,太惨了)
设置 通知 Webhook URL:去企业微信创建一个机器人就能获取了
啊,什么,,,,,,,我tm{:17_1054:}
# -*- coding: utf8 -*-
# python >=3.8
import requests
from datetime import datetime, timedelta
# 固定的出生日期和退休年龄
birth_date_str = "2000/01/01"
retirement_age = 65
# 解析出生日期
birth_date = datetime.strptime(birth_date_str, "%Y/%m/%d")
# 计算退休日期
retirement_date = birth_date.replace(year=birth_date.year + retirement_age)
# 计算剩余时间
today = datetime.now()
time_difference = retirement_date - today
if time_difference.total_seconds() < 0:
result = "您已经达到了退休年龄。"
else:
years = retirement_date.year - today.year
months = retirement_date.month - today.month
days = retirement_date.day - today.day
hours = retirement_date.hour - today.hour
minutes = retirement_date.minute - today.minute
seconds = retirement_date.second - today.second
if seconds < 0:
seconds += 60
minutes -= 1
if minutes < 0:
minutes += 60
hours -= 1
if hours < 0:
hours += 24
days -= 1
if days < 0:
previous_month = retirement_date.replace(day=1) - timedelta(days=1)
days += previous_month.day
months -= 1
if months < 0:
months += 12
years -= 1
result = f"距离退休日期 {retirement_date.strftime('%Y/%m/%d')} 还有: {years} 年, {months} 月, {days} 天, {hours} 小时, {minutes} 分钟, {seconds} 秒。"
# 企业微信机器人 Webhook URL
weixin_webhook_url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"
# 推送到企业微信机器人
payload = {
"msgtype": "text",
"text": {
"content": result
}
}
response = requests.post(weixin_webhook_url, json=payload)
if response.status_code == 200:
print("消息推送成功")
else:
print(f"消息推送失败,状态码: {response.status_code}, 返回信息: {response.text}")
35被优化倒计时可能更有用{:301_1008:} 给你个思路多设计几个,考试倒计时,比如一建一造等。。经济师、社工等
或者直接取名:一建拿证倒计时这种。。哈哈。应该很受欢迎、 用法各式各样;我挂在一台windwos服务器上,计划任务,每天提醒{:17_1084:} 每天看着感觉遥遥无期呀:lol 有点扎心 有没有失业倒计时哈哈 hhh233zxx 发表于 2024-7-26 11:49
35被优化倒计时可能更有用
我快了,坐等被优化,拿点赔偿走人,全国钓鱼去 没想到还会有人做这个东西 脑洞大开 十几年,洗洗睡吧 本来打算恶心老板,结果看这剩余时长恶心到了自己