|
import streamlit as st |
|
import pronotepy |
|
|
|
def load_discussions(client): |
|
|
|
return client.discussions() |
|
|
|
def display_discussion(discussion): |
|
|
|
for message in discussion.messages: |
|
author = "Vous" if message.author is None else message.author |
|
st.markdown(f"##### **{author}**:") |
|
st.markdown(f"> {message.content}") |
|
st.caption(f"*Envoyé le {message.date.strftime('%d/%m/%Y à %H:%M')}*") |
|
st.markdown("---") |
|
|
|
def app(client): |
|
st.title('📧 Messagerie Pronote') |
|
|
|
if not client.logged_in: |
|
st.error("🔴 Veuillez vous connecter pour accéder à la messagerie.") |
|
return |
|
|
|
discussions = load_discussions(client) |
|
|
|
|
|
discussion_subjects = [d.subject for d in discussions] |
|
choice = st.selectbox("💬 Choisissez une discussion", ["Nouvelle discussion..."] + discussion_subjects) |
|
|
|
if choice == "Nouvelle discussion...": |
|
|
|
subject = st.text_input("#️⃣ Sujet") |
|
message = st.text_area("📟 Message") |
|
recipients = client.get_recipients() |
|
recipient_names = [f"{r.name} ({r.type})" for r in recipients] |
|
selected_recipient = st.selectbox("🧷 Destinataire", recipient_names) |
|
if st.button("📤 Envoyer"): |
|
selected_index = recipient_names.index(selected_recipient) |
|
client.new_discussion(subject, message, [recipients[selected_index]]) |
|
st.success("📨 Discussion créée avec succès.") |
|
else: |
|
|
|
selected_discussion = discussions[discussion_subjects.index(choice)] |
|
display_discussion(selected_discussion) |
|
|
|
|
|
reply_message = st.text_area("📟 Votre message") |
|
if st.button("📤 Répondre"): |
|
selected_discussion.reply(reply_message) |
|
st.success("📨 Message envoyé.") |