@@ -38,10 +38,11 @@ def get_notes_content():
3838 'Sec-Fetch-User' : '?1' ,
3939 'Cache-Control' : 'max-age=0'
4040 }
41- response = requests .get (URL , headers = headers , timeout = 30 )
41+ response = requests .get (URL , headers = headers , timeout = 30 , verify = True )
4242
4343 if response .status_code != 200 :
44- raise Exception (f"Erreur lors de la récupération des notes: { response .status_code } - { response .text } " )
44+ error_text = response .text [:500 ] # Limiter la longueur du message d'erreur
45+ raise Exception (f"Erreur lors de la récupération des notes: { response .status_code } - { error_text } " )
4546 response .raise_for_status ()
4647 return response .text
4748
@@ -139,26 +140,9 @@ def send_notification(change):
139140 print ()
140141 print ("DEBUG : {e}" )
141142
142- def main ():
143- while True :
144- now = datetime .datetime .now ()
145- # Mode DEBUG : exécution toutes les 30 secondes, sans contrainte d'heure
146- if LOG_LEVEL == "DEBUG" :
147- interval = 30
148- else :
149- # Si on est hors de la plage minuit-7h, on attend jusqu'à minuit
150- if not (0 <= now .hour < 3 ):
151- next_midnight = (now + datetime .timedelta (days = 1 )).replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
152- sleep_seconds = (next_midnight - now ).total_seconds ()
153- print (f"Hors plage horaire, dodo jusqu'à minuit ({ next_midnight .strftime ('%Y-%m-%d %H:%M:%S' )} )" )
154- time .sleep (sleep_seconds )
155- continue
156- interval = CHECK_INTERVAL
157- # Si on est entre 1h20 et 1h40, on attend 2 minutes
158- now_tz = get_tz_time ()
159- if now_tz .hour == 1 and 20 <= now_tz .minute < 40 :
160- interval = 120
161-
143+ def check_notes ():
144+ """Fonction pour vérifier et traiter les notes"""
145+ try :
162146 # Récupérer le contenu des notes
163147 content = get_notes_content ()
164148 current_time = get_tz_time ().strftime ("%Y-%m-%d %H:%M:%S" )
@@ -171,7 +155,7 @@ def main():
171155 parse .convert_notes_to_json (content , STORAGE_NOTES_JSON_2 )
172156 if not os .path .exists (STORAGE_NOTES_JSON_2 ):
173157 print (f"Erreur : le fichier { STORAGE_NOTES_JSON_2 } n'a pas été créé." )
174- continue
158+ return
175159
176160 new_notes = comparator .load_notes_json (STORAGE_NOTES_JSON_2 )
177161
@@ -194,6 +178,35 @@ def main():
194178 if os .path .exists (STORAGE_NOTES_JSON ):
195179 os .remove (STORAGE_NOTES_JSON )
196180 shutil .move (STORAGE_NOTES_JSON_2 , STORAGE_NOTES_JSON )
181+ except Exception as e :
182+ print (f"Erreur lors de la vérification des notes: { e } " )
183+
184+ def main ():
185+ # Premier check automatique au lancement
186+ print ("🚀 Premier check automatique au lancement du conteneur..." )
187+ check_notes ()
188+ print ()
189+
190+ while True :
191+ now = datetime .datetime .now ()
192+ # Mode DEBUG : exécution toutes les 30 secondes, sans contrainte d'heure
193+ if LOG_LEVEL == "DEBUG" :
194+ interval = 30
195+ else :
196+ # Si on est hors de la plage minuit-7h, on attend jusqu'à minuit
197+ if not (0 <= now .hour < 3 ):
198+ next_midnight = (now + datetime .timedelta (days = 1 )).replace (hour = 0 , minute = 0 , second = 0 , microsecond = 0 )
199+ sleep_seconds = (next_midnight - now ).total_seconds ()
200+ print (f"Hors plage horaire, dodo jusqu'à minuit ({ next_midnight .strftime ('%Y-%m-%d %H:%M:%S' )} )" )
201+ time .sleep (sleep_seconds )
202+ continue
203+ interval = CHECK_INTERVAL
204+ # Si on est entre 1h20 et 1h40, on attend 2 minutes
205+ now_tz = get_tz_time ()
206+ if now_tz .hour == 1 and 20 <= now_tz .minute < 40 :
207+ interval = 120
208+
209+ check_notes ()
197210
198211 next_time = get_tz_time () + datetime .timedelta (seconds = interval )
199212 print ("Prochain check à" , next_time .strftime ("%Y-%m-%d %H:%M:%S" ))
0 commit comments