Résolution des conflits Git et nettoyage du code
This commit is contained in:
18
.env
Normal file
18
.env
Normal file
@@ -0,0 +1,18 @@
|
||||
DB_HOST=54.36.188.119
|
||||
DB_USER=michel
|
||||
DB_PASSWORD=#SO2&1nf%mZ@jfh
|
||||
DB_NAME= SG
|
||||
|
||||
MQTT_HOST=54.36.188.119
|
||||
MQTT_USER=Bwps
|
||||
MQTT_PASSWORD=scJ5ACj2keRfI^
|
||||
|
||||
# === EMAIL SMTP ===# === EMAIL SMTP ===
|
||||
SMTP_HOST=smtp.mail.ovh.net
|
||||
SMTP_PORT=465
|
||||
SMTP_USER=alertes_saclay@domo91.fr
|
||||
SMTP_PASSWORD=Kdpke674y23Feq^H
|
||||
EMAIL_FROM=alertes_saclay@domo91.fr
|
||||
EMAIL_SACLAY=Cuisine <cuisine@bw-paris-saclay.com>
|
||||
EMAIL_MEUDON=meudon@domo91.fr
|
||||
EMAIL_DEFAULT=admin@domo91.fr
|
||||
2
.idea/Fichiers_perso.iml
generated
2
.idea/Fichiers_perso.iml
generated
@@ -2,7 +2,7 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (Gestion sondes) (2)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.13 (Best_Western) (2)" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (Gestion sondes) (2)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -1,5 +1,4 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
# Remplace par ton token de bot Telegram
|
||||
token = "8128378340:AAF2sO3gaH1XpMNya_pEslzerqokoCiFRGs"
|
||||
|
||||
@@ -1,87 +1,75 @@
|
||||
# Insertion de données da l'app SG.
|
||||
# Fichier démarré avec la commande dans le terminal >streamlit run Societe_Generale.py
|
||||
import streamlit as st
|
||||
import mysql.connector
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# Chargement des variables d'environnement
|
||||
load_dotenv()
|
||||
|
||||
st.set_page_config(page_title="Insertion Mysql", layout="centered")
|
||||
st.title("🗓️ Insertion dans une base MySQL")
|
||||
st.title("📄 Insertion dans SG.Emprunts")
|
||||
|
||||
# Charger les identifiants
|
||||
DB_HOST = ("54.36.188.119")
|
||||
DB_USER = ("michel")
|
||||
DB_PASSWORD = ("#SO2&1nf%mZ@jfh")
|
||||
|
||||
# Connexion sans DB initiale pour lister les bases
|
||||
@st.cache_data
|
||||
def get_databases():
|
||||
# Connexion directe à la base SG
|
||||
conn = mysql.connector.connect(
|
||||
host=DB_HOST,
|
||||
user=DB_USER,
|
||||
password=DB_PASSWORD
|
||||
host=os.getenv("DB_HOST"),
|
||||
user=os.getenv("DB_USER"),
|
||||
password=os.getenv("DB_PASSWORD"),
|
||||
database="SG" # Nom de la base fixe
|
||||
)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SHOW DATABASES")
|
||||
bases = [db[0] for db in cursor.fetchall()]
|
||||
conn.close()
|
||||
return bases
|
||||
|
||||
# Connexion avec DB sélectionnée
|
||||
def connect_to_db(db_name):
|
||||
return mysql.connector.connect(
|
||||
host=DB_HOST,
|
||||
user=DB_USER,
|
||||
password=DB_PASSWORD,
|
||||
database=db_name
|
||||
)
|
||||
# Table fixe
|
||||
table = "Emprunts"
|
||||
|
||||
# --- Interface principale ---
|
||||
|
||||
base = st.selectbox("Choisir une base de données", get_databases())
|
||||
if base:
|
||||
conn = connect_to_db(base)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SHOW TABLES")
|
||||
tables = [table[0] for table in cursor.fetchall()]
|
||||
table = st.selectbox("Choisir une table", tables)
|
||||
|
||||
if table:
|
||||
# Lecture des colonnes de la table
|
||||
cursor.execute(f"DESCRIBE {table}")
|
||||
colonnes = cursor.fetchall()
|
||||
|
||||
# Détection clé primaire
|
||||
# Détection de la clé primaire
|
||||
cursor.execute(f"SHOW INDEX FROM {table} WHERE Key_name = 'PRIMARY'")
|
||||
pk = cursor.fetchone()
|
||||
primary_key = pk[4] if pk else None
|
||||
|
||||
# Sélection champ date
|
||||
champ_date_candidates = [col[0] for col in colonnes if "date" in col[1].lower()]
|
||||
champ_date = st.selectbox("Champ de date", champ_date_candidates)
|
||||
|
||||
# Paramètres d’insertion
|
||||
nb_mois = st.number_input("Nombre d'insertions mensuelles", 1, 36, 6)
|
||||
date_depart = st.date_input("Date de départ des insertions", value=datetime.today().date())
|
||||
st.subheader("Champs à insérer (hors clé primaire et champ de date)")
|
||||
champs_choisis = []
|
||||
|
||||
# Champs modifiables
|
||||
champs_editables = [col for col in colonnes if col[0] != primary_key and col[0] != champ_date]
|
||||
champs_choisis = []
|
||||
st.subheader("Champs à insérer (hors clé primaire et champ de date)")
|
||||
for col in champs_editables:
|
||||
if st.checkbox(f"{col[0]} ({col[1]})", value=True):
|
||||
champs_choisis.append(col[0])
|
||||
|
||||
with st.form("formulaire_insertion"):
|
||||
# Formulaire principal
|
||||
if champs_choisis:
|
||||
with st.form(key="formulaire_emprunts"):
|
||||
st.markdown("**Valeurs fixes pour les champs cochés**")
|
||||
valeurs_fixes = {}
|
||||
for nom in champs_choisis:
|
||||
val = st.text_input(nom)
|
||||
valeurs_fixes[nom] = val if val != "" else None
|
||||
|
||||
for champ in champs_choisis:
|
||||
col_type = next((c[1] for c in colonnes if c[0] == champ), "").lower()
|
||||
|
||||
if "int" in col_type:
|
||||
val = st.number_input(champ, step=1)
|
||||
elif "decimal" in col_type or "float" in col_type:
|
||||
val = st.number_input(champ, format="%.2f")
|
||||
else:
|
||||
val = st.text_input(champ)
|
||||
|
||||
valeurs_fixes[champ] = val
|
||||
|
||||
submit = st.form_submit_button("Insérer")
|
||||
|
||||
if submit:
|
||||
try:
|
||||
cursor = conn.cursor()
|
||||
insert_count = 0
|
||||
|
||||
for i in range(nb_mois):
|
||||
year = date_depart.year + (date_depart.month + i - 1) // 12
|
||||
month = (date_depart.month + i - 1) % 12 + 1
|
||||
@@ -100,7 +88,3 @@ if base:
|
||||
|
||||
except Exception as e:
|
||||
st.error(f"❌ Erreur lors de l’insertion : {e}")
|
||||
|
||||
conn.commit()
|
||||
st.success(f"{insert_count} lignes insérées avec succès dans `{table}`.")
|
||||
st.success(f"{insert_count} lignes insérées avec succès.")
|
||||
@@ -1,4 +1,4 @@
|
||||
# Gestion des chambres froides & alertes Telegram
|
||||
# -*- coding: utf-8 -*-
|
||||
import requests
|
||||
import mysql.connector
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import paramiko
|
||||
|
||||
# Configuration
|
||||
hostname = "54.36.188.119"
|
||||
port = 22
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
# 📁 Dossier contenant les fichiers de logs
|
||||
DOSSIER_LOGS = "/var/log"
|
||||
|
||||
@@ -19,12 +19,12 @@ date_selection = st.selectbox("📅 Sélectionnez une date :", dates_dispo)
|
||||
lieux = sorted(df["Lieu"].unique())
|
||||
lieu_selection = st.selectbox("📍 Site :", lieux)
|
||||
|
||||
df_filtré = df[(df["Date_str"] == date_selection) & (df["Lieu"] == lieu_selection)]
|
||||
df_filtre = df[(df["Date_str"] == date_selection) & (df["Lieu"] == lieu_selection)]
|
||||
|
||||
sondes = sorted(df_filtré["Sonde"].unique())
|
||||
sondes = sorted(df_filtre["Sonde"].unique())
|
||||
sonde_selection = st.selectbox("🧪 Sonde :", sondes)
|
||||
|
||||
df_sonde = df_filtré[df_filtré["Sonde"] == sonde_selection]
|
||||
df_sonde = df_filtre[df_filtre["Sonde"] == sonde_selection]
|
||||
|
||||
# --- Graphique température ---
|
||||
fig, ax = plt.subplots(figsize=(10, 4))
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
colorama==0.4.6
|
||||
cryptography==44.0.2
|
||||
filelock==3.18.0
|
||||
matplotlib==3.10.1
|
||||
mysql_connector_repackaged==0.3.1
|
||||
paho_mqtt==2.1.0
|
||||
pandas==2.2.3
|
||||
paramiko==3.5.1
|
||||
Pillow==11.2.1
|
||||
protobuf==6.30.2
|
||||
pyOpenSSL==25.0.0
|
||||
python-dotenv==1.1.0
|
||||
redis==5.2.1
|
||||
schedule==1.2.2
|
||||
sphinx==8.2.3
|
||||
streamlit==1.44.1
|
||||
urllib3_secure_extra==0.1.0
|
||||
mysql-connector-python~=9.2.0
|
||||
pandas~=2.2.3
|
||||
streamlit~=1.44.1
|
||||
matplotlib~=3.10.1
|
||||
paho-mqtt~=2.1.0
|
||||
requests~=2.32.3
|
||||
schedule~=1.2.2
|
||||
paramiko~=3.5.1
|
||||
dotenv
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# Controle des services supervisor envoi en cas de disfonction et tous les jours à sept heures
|
||||
# a faire tourner avec crontb -e en sudo
|
||||
# */30 * * * * /home/debian/travail/myenv/bin/python3 /home/debian/travail/Scripts/supervisor_watchdog.py
|
||||
import subprocess
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
Reference in New Issue
Block a user