吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6879|回复: 277
收起左侧

[Python 原创] 我宣布了自己死亡--github生命监测

    [复制链接]
jockon 发表于 2026-11-3 18:06
本帖最后由 jockon 于 2026-11-4 06:44 编辑

前一段时间死了么app火了一阵,没想到这么快我就要用上了。作者也得了绝症,也将不久人世,再见了~(无需过问)

自己简单搓了一个非app的,使用github action每天更新状态,action workflow可手动签到或死亡,死亡后自动更新README.md在自己的主页上。
Snipaste_20261103_175250.png

[b]存活判定方式:

  1. workflow 手动签到;
  2. 任务每天执行,7天内没签到默认存活;

活着.png

[b]死亡判定方式:

1.超过7天未手动签到即宣布死亡。
2.手动执行 workflow 立即死亡。
死亡.png

死亡后:
更新首页README,宣布死亡消息(没了)。

因每个人的信息不同,需要修改成自己的,项目名用自己的用户名(这样可以显示在自己主页上)

https://github.com/Zhu-junwei/Zhu-junwei/

自动任务 life-monitor.yml

name: Life Monitor

on:
  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 os
import datetime

BASE_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 = 7
BIRTH_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 None

def 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 content

def 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()

免费评分

参与人数 118吾爱币 +122 热心值 +109 收起 理由
HuLZ2006 + 1 + 1 我很赞同!
Erdon7c + 1 + 1 加油
小懒虫 + 1 + 1 加油
NNovice丶 + 1 + 1 用心讨论,共获提升!
dmxayjn + 1 + 1 加油 向前看!!!!
shenxing + 1 + 1 热心回复!
52pojie10000 + 1 + 1 谢谢@Thanks!
laotzudao0 + 1 + 1 相信奇迹
森罗千引 + 1 + 1 诊断错误,好好活着。加油
Gold9T + 1 热心回复!
a1069942474 + 1 + 1 我很赞同!
745237896 + 1 + 1 谢谢@Thanks!
llee841020 + 1 + 1 我们终将离开 请活好每一天
18637598251 + 1 + 1 老哥,要加油啊,一定会好起来的
naixubao + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
liuxdsuyr + 1 兄弟,加油,干一天就胜利一天,每天都是新的
Dove702 + 1 + 1 加油!!!
fz52033 + 1 + 1 快点好起来,不要放弃
Scpkisl + 1 不要放弃!
雨濄添情 + 1 + 1 加油,不要放弃
安道尔的鱼 + 1 + 1 热心回复!
fz74110 + 2 + 1 兄弟,加油,
xizevip + 1 + 1 加油!
johnson1007 + 1 ,,,
styphen + 1 + 1 加油,兄弟
zch_546 + 1 + 1 愿平安!
lan74444 + 1 + 1 热心回复!
theStyx + 1 + 1 热心回复!
kanbekotaro + 1 鎰熻阿鍙戝竷鍘熷垱浣滃搧锛屽惥鐖辩牬瑙h鍧涘洜浣犳洿绮惧僵锛?
shiyue2925 + 1 + 1 谢谢@Thanks!
lianyuposui + 1 + 1 热心回复!
wangzhizhuo + 1 + 1 同95的,非常遗憾,兄弟加油啊!
sightwww + 1 + 1 唉。。。
kaixinmoney + 1 + 1 楼主,过开心点
天使大叔 + 1 + 1 加油兄弟
yxpp + 1 谢谢@Thanks!
caishubao + 1 + 1 加油
我哭了你呢 + 1 + 1 加油兄弟,一定要一直更下去
ycat + 2 + 1 加油
lxc66 + 1 + 1 好好活,兄弟。
yamik + 1 + 1 加油活下去!如果能加个留言板的话,赛博与灵魂可互通
mydhx + 1 + 1 热心回复!
ziyuejun + 1 加油!希望这个你永远用不到
joker78 + 2 + 1 加油,,,
专属_lzy + 1 + 1 加油!别放弃!!!!!
Indra + 1 谢谢@Thanks!
ysq151 + 2 + 1 兄弟,希望你是说谎的
qilin1031 + 1 + 1 加油加油!
yukon8888 + 1 + 1 用心讨论,共获提升!
lzp88124 + 2 + 1 兄弟,加油
gold123 + 1 + 1 谢谢@Thanks!
and11 + 1 + 1 我很赞同!
15603940543 + 1 + 1 小兄弟,加油!
sergin + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
orz4260 + 2 + 1 加油,兄弟!!!
wangasd + 1 + 1 兄弟,加油!!!
Yiduoyun7 + 1 + 1 楼主,过开心点
kacyd + 1 + 1 加油!!
wshr007 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!保护好身体,别加班写东西了, ...
ToT、 + 2 + 1 鼓励转贴优秀软件安全工具和文档!
ychcz77 + 1 + 1 加油!生命永不停止
spss1019 + 1 + 1 相信有奇迹
人文气息 + 1 + 1 谢谢@Thanks!
yebanfm + 1 + 1 加油~
噗嗤大叔 + 1 + 1 兄弟 加油加油加油!
谢单单 + 1 + 1 加油
翩跹丶 + 1 + 1 希望这两个评分值能给你带来哪怕一秒的开心
缘木求鱼啦 + 1 + 1 加油啊!
xy2018888 + 1 谢谢@Thanks!
後天 + 1 + 1 用自己喜欢的方式活吧..
wenlik + 1 + 1 加油,小兄弟
lkb00077 + 1 加油!别放弃
Sixpence + 1 + 1 谢谢@Thanks!
xlwllm + 1 + 1 谢谢@Thanks!
vlricchen + 1 + 1 不枉人间走一遭,加油!
ma1138 + 1 + 1 加油!!!
hinsley + 1 + 1 我很赞同!
bugof52pj + 1 加油
Lsygood + 1 + 1 热心回复!
ghostscorpion + 1 + 1 我很赞同!
meigong + 1 + 1 热心回复!
bbb11120 + 1 + 1 我很赞同!
tooooony + 1 + 1 我很赞同!
loginnow + 1 + 1 +U!!!争一口气
myFreefly + 1 + 1 死亡留痕,证明此生来过!
WAyh2026Xlbzn + 1 + 1 加油,坚持住
wontbackdown + 1 + 1 加油!
kunsir001 + 1 + 1 加油
Xiaomai88 + 1 + 1 加油!啊
lizy169 + 1 + 1 加油!
痴情的老实人 + 1 + 1 谢谢@Thanks!
守恒 + 1 我尿毒症血液透析整整20年了加油兄弟
sunflash + 1 + 1 祝精神永生
lykm900 + 1 + 1 加油,别那么悲观
ZisGnomeshgh + 1 + 1 兄弟加油!
qu1eRo + 1 加油
诺十年以后 + 1 + 1 加油&amp;amp;#1641;(&amp;amp;#3665;&amp;amp;#10075;&amp;amp;#7447;&amp;amp;#10075;&amp;amp;#3665
sanyezaofang + 1 + 1 兄弟 辛苦了
520521314 + 1 + 1 加油
jiarenlu + 1 加油

查看全部评分

发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

汇成河流 发表于 2026-11-4 08:05
建议可以增加一个自己留言的功能,说一些想说的话,也可以开其他人留言的功能,但自己和别人的分页面存放,再留一个墓志铭在显眼位置,还能再开发一个网络墓地,存放在区块链
洞见未来 发表于 2026-11-3 19:15
现在很多癌症有对应的靶向药,多了解了解,加油,我邻居肺癌转移,在靶向药治疗下,目前和正常人一样生活快5年了。
chaogezi333 发表于 2026-11-3 18:22
江湖凡凡 发表于 2026-11-3 18:17
加油老哥。
 楼主| jockon 发表于 2026-11-6 18:00
谢谢各位的鼓励,统一回复一下,我没有开玩笑,得的是脑干的弥漫性胶质瘤,3级或以上,位置特殊不能手术,从感觉不舒服到现在一共也就经历了两个多月,后面可能会经历一段时间放化疗,在化验病理找靶向药,不过这都是徒劳而已,生命就是那么充满戏剧性。

选github是因为这个平台可能不会那么容易关闭吧,也就是图个乐呵。手动签到、死亡,只是方便家人帮做一下,自动的任务执行怕忘记了有一个执行的空间。程序本身并不重要。

至于有人的建议加什么功能什么的,实在是没有精力管这个了,就这样吧。

点评

加油 兄弟~~去北京天坛医院看看~!!  发表于 2026-11-7 00:24
地瓜君 发表于 2026-11-3 18:15
加油啊哥们!
MRBANK 发表于 2026-11-3 18:18
加油啊~
bigmuzzy 发表于 2026-11-3 18:21
加油老哥。加油!
congheerlai 发表于 2026-11-3 18:21
看到这个标题 心里紧了一下~ 哎
yixinyingX 发表于 2026-11-3 18:22
加油呀,坚持住!!!
woaininiaiwo 发表于 2026-11-3 18:41
哥们!加油,一切都会好起来的
ghostOfTheWolf 发表于 2026-11-3 18:46
加油啊 兄弟.要坚持下去.万一呢
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-11-7 05:15

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表