|
import streamlit as st |
|
from pronotepy import Client |
|
import datetime |
|
|
|
def app(client: Client): |
|
st.title('ℹ️ Informations et Enquêtes') |
|
|
|
|
|
search_query = st.text_input("🔍 Recherche", "") |
|
|
|
try: |
|
|
|
informations = client.information_and_surveys() |
|
|
|
|
|
mois_annee_scolaire_noms = ["✨ Toutes les infos", "1️⃣ Septembre", "2️⃣ Octobre", "3️⃣ Novembre", "4️⃣ Décembre", |
|
"5️⃣ Janvier", "6️⃣ Février", "7️⃣ Mars", "8️⃣ Avril", "9️⃣ Mai", "🔟 Juin", "🔟 Juillet"] |
|
|
|
|
|
tabs = st.tabs(mois_annee_scolaire_noms) |
|
|
|
for i, tab in enumerate(tabs): |
|
with tab: |
|
if i == 0: |
|
display_monthly_info(informations, search_query) |
|
else: |
|
mois = i + 8 if i < 5 else i - 4 |
|
infos_du_mois = [info for info in informations if info.creation_date and info.creation_date.month == mois] |
|
display_monthly_info(infos_du_mois, search_query) |
|
|
|
except Exception as e: |
|
st.error("⚠️ Une erreur s'est produite lors de la récupération des informations.") |
|
st.error(str(e)) |
|
|
|
|
|
def display_monthly_info(informations, search_query): |
|
filtered_infos = search_informations(informations, search_query) |
|
sorted_infos = sorted(filtered_infos, key=lambda x: x.creation_date, reverse=True) |
|
|
|
if not sorted_infos: |
|
st.info("🔴 Aucune information trouvée.") |
|
else: |
|
for info in sorted_infos: |
|
display_information(info) |
|
|
|
def search_informations(informations, query): |
|
return [info for info in informations if query.lower() in (info.content or '').lower() |
|
or query.lower() in (info.category or '').lower() |
|
or query.lower() in (info.author or '').lower() |
|
or query in (info.creation_date.strftime('%Y-%m-%d') if info.creation_date else '')] |
|
|
|
|
|
def display_information(info): |
|
creation_date = info.creation_date.strftime('%Y-%m-%d') if info.creation_date else 'Inconnue' |
|
content_formatted = info.content.replace('\n', '<br>') |
|
|
|
with st.expander(f"{info.title} - {info.author}", expanded=not info.read): |
|
st.markdown(f""" |
|
- _**Auteur**: {info.author} | **Date de Création**: {creation_date} | **Catégorie**: {info.category}_ |
|
--- |
|
{content_formatted} |
|
""", unsafe_allow_html=True) |
|
if not info.read: |
|
if st.button('Marquer comme lu', key=info.id): |
|
info.mark_as_read(True) |
|
st.rerun() |