我宣布了自己死亡--github生命检测
作者:小编日期:2026-11-04浏览:20分类:只有源码
前一段时间死了么app火了一阵,没想到这么快我就要用上了。作者也得了绝症,也将不久人世,再见了~(无需过问)
自己简单搓了一个非app的,使用github action每天更新状态,action workflowk可手动签到或死亡,死亡后自动更新README.md在自己的主页上。
存活判定方式: workflowk 手动签到; 任务每天执行,7天内没签到默认存活;
死亡判定方式:
1.超过7天未手动签到即宣布死亡。
2.手动执行 workflowk 立即死亡。
死亡后:
更新首页README,宣布死亡消息(没了)。
因每个人的信息不同,需要修改成自己的,项目名用自己的用户名(这样可以显示在自己主页上)
https://github.com/Zhu-junwei/Zhu-junwei/
自动任务 life-monitor.ymlname: Life Monitoron: schedule: - cron: '00 19 * * *' workflow_dispatch: inputs: mode: description: '选择运行模式' required: true type: choice options: - 签到 - 死亡jobs: monitor: runs-on: ubuntu-24.04 permissions: contents: write steps: - name: Checkout uses: actions/checkout@v6 - name: Setup Python uses: actions/setup-python@v7.1.0 with: python-version: '3.13' - name: Run life monitor run: | MODE="${{ github.event.inputs.mode }}" if [ "$MODE" = "签到" ]; then python life_monitor.py elif [ "$MODE" = "死亡" ]; then python life_monitor.py --force-death else # 定时触发:只检查不签到,超过7天自动宣告死亡 python life_monitor.py --auto fi - name: Commit and push run: | MODE="${{ github.event.inputs.mode }}" MSG="${MODE:-自动签到}" git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add README.md .last_run git diff --cached --quiet || git commit -m "life monitor: $MSG" git push复制代码死亡逻辑life_monitor.py#!/usr/bin/env python3"""生命监测系统"""import osimport datetimeBASE_DIR = os.path.dirname(os.path.abspath(__file__))STATE_FILE = os.path.join(BASE_DIR, ".last_run")README_PATH = os.path.join(BASE_DIR, "README.md")MAX_DAYS = 7BIRTH_DATE = datetime.date(1995, 4, 23)BJ = datetime.timezone(datetime.timedelta(hours=8))def read_last_run(): if not os.path.exists(STATE_FILE): return None try: with open(STATE_FILE, "r", encoding="utf-8") as f: raw = f.read().strip() dt = datetime.datetime.fromisoformat(raw) if dt.tzinfo is None: dt = dt.replace(tzinfo=BJ) return dt except Exception: return Nonedef write_last_run(dt): with open(STATE_FILE, "w", encoding="utf-8") as f: f.write(dt.isoformat())def now(): return datetime.datetime.now(BJ)def generate_alive_content(last_run, days, scan_time): lines = [ f"🟢 上次存活时间: {last_run.strftime('%Y-%m-%d %H:%M:%S')} (UTC+8)", "", f"更新时间: {scan_time.strftime('%Y-%m-%d %H:%M:%S')} (UTC+8)", ] return "\n".join(lines)def generate_obituary_content(last_run, days, scan_time, force_death=False): birth = BIRTH_DATE if force_death: # 手动确认死亡:死亡日期为当前扫描日期,保留真实最后存活时间 death_date = scan_time.date() death_detail = "" death_reason = "手动确认死亡。" days_line = f"> **距上次执行**: {days} 天" else: # 自动判定死亡:超过阈值,估算死亡日期 death_date = (last_run + datetime.timedelta(days=MAX_DAYS)).date() death_detail = f"(最后手动执行后第 {MAX_DAYS} 天(估算))" death_reason = f"超过 {MAX_DAYS} 天未检测到生命体征,按协议发布讣告。" days_line = f"> **距上次执行**: {days} 天" age = death_date.year - birth.year - ((death_date.month, death_date.day) < (birth.month, birth.day)) with open(os.path.join(BASE_DIR, "obituary.md"), "r", encoding="utf-8") as f: content = f.read() replacements = { "{{BIRTH_DATE}}": birth.strftime('%Y-%m-%d'), "{{BIRTH_LUNAR}}": "农历一九九五年三月廿四", "{{NAME}}": "朱俊伟", "{{DEATH_DATE}}": death_date.strftime('%Y-%m-%d'), "{{AGE}}": str(age), "{{MAX_DAYS}}": str(MAX_DAYS), "{{LAST_RUN}}": last_run.strftime('%Y-%m-%d %H:%M:%S'), "{{SCAN_TIME}}": scan_time.strftime('%Y-%m-%d %H:%M:%S'), "{{DEATH_DETAIL}}": death_detail, "{{DEATH_REASON}}": death_reason, "{{DAYS_LINE}}": days_line, } for key, value in replacements.items(): content = content.replace(key, value) return contentdef run(): import sys auto_mode = "--auto" in sys.argv force_death = "--force-death" in sys.argv scan_time = now() last_run = read_last_run() if force_death: # 死亡模式:不修改 .last_run,保留真实的上次存活时间 # 如果没有历史记录,用当前时间兜底 if last_run is None: last_run = scan_time elif not auto_mode: # 手动签到:更新 .last_run 为当前时间 write_last_run(scan_time) last_run = scan_time if last_run is None: days = 0 if force_death: # 没有历史记录但手动确认死亡 content = generate_obituary_content(scan_time, days, scan_time, force_death) else: content = generate_alive_content(scan_time, days, scan_time) else: days = (scan_time - last_run).days if force_death: # 手动确认死亡:直接生成讣告,不经过阈值判断 print(f"💀 手动确认死亡。最后存活时间: {last_run.strftime('%Y-%m-%d %H:%M:%S')}") content = generate_obituary_content(last_run, days, scan_time, force_death) elif days > MAX_DAYS: print(f"⚠️ 距上次手动执行已过去 {days} 天,超过 {MAX_DAYS} 天阈值!") content = generate_obituary_content(last_run, days, scan_time, force_death) else: print(f"✅ 距上次手动执行 {days} 天,在 {MAX_DAYS} 天阈值内。") content = generate_alive_content(last_run, days, scan_time) with open(README_PATH, "w", encoding="utf-8") as f: f.write(content) print(f"📝 README.md 已更新") print(f" 间隔: {days} 天 | 模式: {'自动检查' if auto_mode else ('强制死亡' if force_death else '手动打卡')}") print(f" 状态: {'讣告' if last_run and days > MAX_DAYS else '正常'}")if __name__ == "__main__": run()复制代码
相关文章
- 11-04 我宣布了自己死亡--github生命检测
- 10-28 AI综合站商业分发系统v3.1纯净版发布 附完整安装教程(排版修正版)
- 10-28 聊天分析 + 回复建议 + 找话题:微话助手把微x对话变成“可读题”
- 10-28 国产安卓手机去广告 Android Ad Cleaner
- 10-26 豆包去水印网页源码程序
- 10-26 最新2077高定网址导航系统源码 全开源
- 10-26 一键部署星播直播系统源码
- 10-26 吃瓜主题3.0视频源码
- 10-25 海洋个人引导页4迎新版【开源】
- 10-25 聚绘阁最app下载页源码
- 10-17 Ai一句话生成网站带卡密续费功能
- 10-17 ZO论坛盒子正式开源:基于 Electron 的 Discuz 桌面客户端,附后台接口与部署文档
取消回复欢迎你发表评论:
- 协助本站优化一下
- 最近发表
- 1魔方4K影视V3.3.2 主打海量资源与纯净体验
- 2粉猪影视V1.0.8 海量好剧集随心看
- 3苍云阅读V1.5.3 海量小说免费看
- 4【一键书阁】1.6.3 正版资源免费看 功能全解锁
- 5【当鸟动漫】1.0.11 二次元聚集地 追番神器 无广告
- 6UU远程v4.45.0 手机远程控制电脑 远程操控 文件互传
- 7我宣布了自己死亡--github生命检测
- 8咸鱼影视V4.0.9 海量影视免费看
- 9甜瓜小说V3.3.2 免费阅读神器
- 10音序V1.1.4 海量歌曲在线畅听
- 11寻书阁V1.0.4 海量网文资源
- 12【哐哐追剧】1.2.0 海量影视免费看 资源实时更新
- 13【myMusic】1.0 免费音乐app 无损音质 音源超级多
- 14彩虹视频V4.3.0 海量国内外热门剧集
- 15抱走漫画V1.0.6 海量高清漫画随心追
Copyright© XGW9.COM版权所有〖小庚资源网〗
〖恒创科技〗为本站提供专业云计算服务
本站发布的内容来源于互联网,如果有侵权内容,请联系我们删除!E-mail:xgzyw6@outlook.com
关于我们|我要投稿|免责声明|XML地图









暂无评论,来添加一个吧。