feat(echo-self): tehnici pauza random din fisier
- Creat memory/tehnici-pauza.md cu banca de tehnici (BIROU + ACASA) - Creat tools/pauza_random.py - alege random in functie de ora - Actualizat job respiratie-orar sa foloseasca scriptul - Actualizat job evening-coaching sa actualizeze automat fisierul din insights
This commit is contained in:
119
tools/pauza_random.py
Normal file
119
tools/pauza_random.py
Normal file
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Alege o tehnică de pauză random din memory/tehnici-pauza.md
|
||||
În funcție de ora curentă (București = UTC+2):
|
||||
- 09:00-17:00 → BIROU
|
||||
- 18:00+ → ACASĂ
|
||||
"""
|
||||
|
||||
import random
|
||||
import re
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
|
||||
# Timezone București (UTC+2, simplificat)
|
||||
TZ_OFFSET = timedelta(hours=2)
|
||||
|
||||
def get_bucharest_hour():
|
||||
"""Returnează ora curentă în București."""
|
||||
utc_now = datetime.now(timezone.utc)
|
||||
bucharest_now = utc_now + TZ_OFFSET
|
||||
return bucharest_now.hour
|
||||
|
||||
def parse_tehnici(filepath):
|
||||
"""Parsează fișierul și returnează dict cu BIROU și ACASA."""
|
||||
content = Path(filepath).read_text(encoding='utf-8')
|
||||
|
||||
tehnici = {'BIROU': [], 'ACASA': []}
|
||||
current_section = None
|
||||
current_tehnica = None
|
||||
current_details = []
|
||||
|
||||
for line in content.split('\n'):
|
||||
# Detectează secțiunea
|
||||
if '## BIROU' in line:
|
||||
current_section = 'BIROU'
|
||||
continue
|
||||
elif '## ACASĂ' in line or '## ACASA' in line:
|
||||
current_section = 'ACASA'
|
||||
continue
|
||||
elif line.startswith('## ') or line.startswith('---'):
|
||||
# Altă secțiune (Surse, etc.) - oprește parsarea
|
||||
if current_section and current_tehnica:
|
||||
tehnici[current_section].append({
|
||||
'titlu': current_tehnica,
|
||||
'detalii': '\n'.join(current_details).strip()
|
||||
})
|
||||
current_section = None
|
||||
continue
|
||||
|
||||
if not current_section:
|
||||
continue
|
||||
|
||||
# Detectează titlu tehnică (### Titlu)
|
||||
if line.startswith('### '):
|
||||
# Salvează tehnica anterioară
|
||||
if current_tehnica:
|
||||
tehnici[current_section].append({
|
||||
'titlu': current_tehnica,
|
||||
'detalii': '\n'.join(current_details).strip()
|
||||
})
|
||||
current_tehnica = line[4:].strip()
|
||||
current_details = []
|
||||
elif line.startswith('- ') and current_tehnica:
|
||||
# Detaliu (bullet point)
|
||||
current_details.append(line[2:].strip())
|
||||
|
||||
# Salvează ultima tehnică
|
||||
if current_section and current_tehnica:
|
||||
tehnici[current_section].append({
|
||||
'titlu': current_tehnica,
|
||||
'detalii': '\n'.join(current_details).strip()
|
||||
})
|
||||
|
||||
return tehnici
|
||||
|
||||
def formateaza_mesaj(tehnica):
|
||||
"""Formatează tehnica pentru mesaj Discord."""
|
||||
titlu = tehnica['titlu']
|
||||
detalii = tehnica['detalii']
|
||||
|
||||
# Alege un detaliu random dacă sunt mai multe
|
||||
detalii_list = [d for d in detalii.split('\n') if d.strip()]
|
||||
if detalii_list:
|
||||
detaliu = random.choice(detalii_list)
|
||||
# Curăță formatarea markdown
|
||||
detaliu = re.sub(r'\*\*([^*]+)\*\*', r'\1', detaliu)
|
||||
else:
|
||||
detaliu = ""
|
||||
|
||||
return f"**{titlu}.** {detaliu}"
|
||||
|
||||
def main():
|
||||
filepath = Path(__file__).parent.parent / 'agents/echo-self/memory/tehnici-pauza.md'
|
||||
|
||||
if not filepath.exists():
|
||||
print("Fișierul tehnici-pauza.md nu există!")
|
||||
return
|
||||
|
||||
hora = get_bucharest_hour()
|
||||
tehnici = parse_tehnici(filepath)
|
||||
|
||||
# Alege secțiunea în funcție de oră
|
||||
if 9 <= hora <= 17:
|
||||
sectiune = 'BIROU'
|
||||
else:
|
||||
sectiune = 'ACASA'
|
||||
|
||||
if not tehnici[sectiune]:
|
||||
print(f"Nu am tehnici pentru secțiunea {sectiune}!")
|
||||
return
|
||||
|
||||
# Alege o tehnică random
|
||||
tehnica = random.choice(tehnici[sectiune])
|
||||
mesaj = formateaza_mesaj(tehnica)
|
||||
|
||||
print(mesaj)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user