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">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<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" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.13 (Best_Western) (2)" />
|
<option name="sdkName" value="Python 3.13 (Best_Western) (2)" />
|
||||||
</component>
|
</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>
|
</project>
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
|
||||||
|
|
||||||
# Remplace par ton token de bot Telegram
|
# Remplace par ton token de bot Telegram
|
||||||
token = "8128378340:AAF2sO3gaH1XpMNya_pEslzerqokoCiFRGs"
|
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 streamlit as st
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
# Chargement des variables d'environnement
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
st.set_page_config(page_title="Insertion Mysql", layout="centered")
|
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
|
# Connexion directe à la base SG
|
||||||
DB_HOST = ("54.36.188.119")
|
conn = mysql.connector.connect(
|
||||||
DB_USER = ("michel")
|
host=os.getenv("DB_HOST"),
|
||||||
DB_PASSWORD = ("#SO2&1nf%mZ@jfh")
|
user=os.getenv("DB_USER"),
|
||||||
|
password=os.getenv("DB_PASSWORD"),
|
||||||
|
database="SG" # Nom de la base fixe
|
||||||
|
)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# Connexion sans DB initiale pour lister les bases
|
# Table fixe
|
||||||
@st.cache_data
|
table = "Emprunts"
|
||||||
def get_databases():
|
|
||||||
conn = mysql.connector.connect(
|
|
||||||
host=DB_HOST,
|
|
||||||
user=DB_USER,
|
|
||||||
password=DB_PASSWORD
|
|
||||||
)
|
|
||||||
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
|
# Lecture des colonnes de la table
|
||||||
def connect_to_db(db_name):
|
cursor.execute(f"DESCRIBE {table}")
|
||||||
return mysql.connector.connect(
|
colonnes = cursor.fetchall()
|
||||||
host=DB_HOST,
|
|
||||||
user=DB_USER,
|
|
||||||
password=DB_PASSWORD,
|
|
||||||
database=db_name
|
|
||||||
)
|
|
||||||
|
|
||||||
# --- Interface principale ---
|
# 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
|
||||||
|
|
||||||
base = st.selectbox("Choisir une base de données", get_databases())
|
# Sélection champ date
|
||||||
if base:
|
champ_date_candidates = [col[0] for col in colonnes if "date" in col[1].lower()]
|
||||||
conn = connect_to_db(base)
|
champ_date = st.selectbox("Champ de date", champ_date_candidates)
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("SHOW TABLES")
|
# Paramètres d’insertion
|
||||||
tables = [table[0] for table in cursor.fetchall()]
|
nb_mois = st.number_input("Nombre d'insertions mensuelles", 1, 36, 6)
|
||||||
table = st.selectbox("Choisir une table", tables)
|
date_depart = st.date_input("Date de départ des insertions", value=datetime.today().date())
|
||||||
|
|
||||||
if table:
|
# Champs modifiables
|
||||||
cursor.execute(f"DESCRIBE {table}")
|
champs_editables = [col for col in colonnes if col[0] != primary_key and col[0] != champ_date]
|
||||||
colonnes = cursor.fetchall()
|
champs_choisis = []
|
||||||
|
st.subheader("Champs à insérer (hors clé primaire et champ de date)")
|
||||||
# Détection clé primaire
|
for col in champs_editables:
|
||||||
cursor.execute(f"SHOW INDEX FROM {table} WHERE Key_name = 'PRIMARY'")
|
|
||||||
pk = cursor.fetchone()
|
|
||||||
primary_key = pk[4] if pk else None
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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_editables = [col for col in colonnes if col[0] != primary_key and col[0] != champ_date]
|
|
||||||
for col in champs_editables:
|
|
||||||
if st.checkbox(f"{col[0]} ({col[1]})", value=True):
|
if st.checkbox(f"{col[0]} ({col[1]})", value=True):
|
||||||
champs_choisis.append(col[0])
|
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**")
|
st.markdown("**Valeurs fixes pour les champs cochés**")
|
||||||
valeurs_fixes = {}
|
valeurs_fixes = {}
|
||||||
for nom in champs_choisis:
|
|
||||||
val = st.text_input(nom)
|
for champ in champs_choisis:
|
||||||
valeurs_fixes[nom] = val if val != "" else None
|
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")
|
submit = st.form_submit_button("Insérer")
|
||||||
|
|
||||||
|
if submit:
|
||||||
try:
|
try:
|
||||||
cursor = conn.cursor()
|
|
||||||
insert_count = 0
|
insert_count = 0
|
||||||
|
|
||||||
for i in range(nb_mois):
|
for i in range(nb_mois):
|
||||||
year = date_depart.year + (date_depart.month + i - 1) // 12
|
year = date_depart.year + (date_depart.month + i - 1) // 12
|
||||||
month = (date_depart.month + i - 1) % 12 + 1
|
month = (date_depart.month + i - 1) % 12 + 1
|
||||||
@@ -100,7 +88,3 @@ if base:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
st.error(f"❌ Erreur lors de l’insertion : {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 requests
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
hostname = "54.36.188.119"
|
hostname = "54.36.188.119"
|
||||||
port = 22
|
port = 22
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import os
|
|
||||||
import time
|
|
||||||
|
|
||||||
# 📁 Dossier contenant les fichiers de logs
|
# 📁 Dossier contenant les fichiers de logs
|
||||||
DOSSIER_LOGS = "/var/log"
|
DOSSIER_LOGS = "/var/log"
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ date_selection = st.selectbox("📅 Sélectionnez une date :", dates_dispo)
|
|||||||
lieux = sorted(df["Lieu"].unique())
|
lieux = sorted(df["Lieu"].unique())
|
||||||
lieu_selection = st.selectbox("📍 Site :", lieux)
|
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)
|
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 ---
|
# --- Graphique température ---
|
||||||
fig, ax = plt.subplots(figsize=(10, 4))
|
fig, ax = plt.subplots(figsize=(10, 4))
|
||||||
|
|||||||
@@ -1,17 +1,10 @@
|
|||||||
colorama==0.4.6
|
mysql-connector-python~=9.2.0
|
||||||
cryptography==44.0.2
|
pandas~=2.2.3
|
||||||
filelock==3.18.0
|
streamlit~=1.44.1
|
||||||
matplotlib==3.10.1
|
matplotlib~=3.10.1
|
||||||
mysql_connector_repackaged==0.3.1
|
paho-mqtt~=2.1.0
|
||||||
paho_mqtt==2.1.0
|
requests~=2.32.3
|
||||||
pandas==2.2.3
|
schedule~=1.2.2
|
||||||
paramiko==3.5.1
|
paramiko~=3.5.1
|
||||||
Pillow==11.2.1
|
dotenv
|
||||||
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
|
|
||||||
|
|||||||
@@ -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 subprocess
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
|
|||||||
Reference in New Issue
Block a user