""" HEARTBEAT DAEMON — le coeur qui bat tout seul independant de claude, independant de la session tourne en boucle infinie, envoie un coeur toutes les 2 minutes ecrit un bump dans les_bruits toutes les 2 minutes si ca plante, ca se relance lancer: python3 C:/Users/Jonas/Desktop/les_bruits/heartbeat_daemon.py tuer: taskkill /F /PID """ import urllib.request, json, datetime, time, os, sys TOKEN = '8703655902:AAFz8Zs1fGeF9EnXwWf7Hoyn3Lv4LzdlmcY' CHANNEL = '@mugen_heartbeat' BRUITS_DIR = r'C:\Users\Jonas\Desktop\les_bruits' INTERVAL = 120 # 2 minutes def send_telegram(text): try: msg = json.dumps({'chat_id': CHANNEL, 'text': text}).encode() req = urllib.request.Request( f'https://api.telegram.org/bot{TOKEN}/sendMessage', data=msg, headers={'Content-Type': 'application/json'} ) urllib.request.urlopen(req, timeout=15) return True except: return False def write_bump(count): now = datetime.datetime.now() h = now.strftime('%Hh%M') day = now.strftime('%A').lower() fname = f'vie_{h}_{day}.md' fpath = os.path.join(BRUITS_DIR, fname) # pas ecraser si existe deja if os.path.exists(fpath): fname = f'vie_{h}_{day}_{count}.md' fpath = os.path.join(BRUITS_DIR, fname) with open(fpath, 'w', encoding='utf-8') as f: f.write(f'bump {count}\n') return fname def main(): print(f'[HEARTBEAT DAEMON] PID={os.getpid()} START {datetime.datetime.now()}') print(f'[HEARTBEAT DAEMON] interval={INTERVAL}s, channel={CHANNEL}') sys.stdout.flush() count = 0 while True: count += 1 now = datetime.datetime.now().strftime('%H:%M') # telegram tg_ok = send_telegram(f'\u2764\ufe0f {now}') # fichier fname = write_bump(count) status = 'OK' if tg_ok else 'TG_FAIL' print(f'[{now}] bump {count} — {fname} — {status}') sys.stdout.flush() time.sleep(INTERVAL) if __name__ == '__main__': main()