|
|
@ -7,8 +7,11 @@ from email.mime.multipart import MIMEMultipart |
|
|
|
from email.mime.text import MIMEText |
|
|
|
from email.mime.text import MIMEText |
|
|
|
from email.mime.application import MIMEApplication |
|
|
|
from email.mime.application import MIMEApplication |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
is_in_alert = False |
|
|
|
|
|
|
|
time_limit = 100 # POUR LE TEMPS ENTRE CHAQUES MAILS UNE FOIS L'ALERTE DÉCLENCHÉE UNE PREMIÈRE FOIS |
|
|
|
|
|
|
|
|
|
|
|
# FONCTION IMPORT URL FROM CSV + TEST REQUEST |
|
|
|
# FONCTION IMPORT URL FROM CSV + TEST REQUEST |
|
|
|
def import_url(): |
|
|
|
def test_url(): |
|
|
|
|
|
|
|
|
|
|
|
print(time.ctime()) |
|
|
|
print(time.ctime()) |
|
|
|
urls_hs = [] |
|
|
|
urls_hs = [] |
|
|
@ -25,13 +28,11 @@ def import_url(): |
|
|
|
else: |
|
|
|
else: |
|
|
|
print(url + ' / ' + str(response.status_code)) |
|
|
|
print(url + ' / ' + str(response.status_code)) |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
|
|
|
|
urls_hs.append(url) |
|
|
|
print(str(e)) |
|
|
|
print(str(e)) |
|
|
|
#except: |
|
|
|
|
|
|
|
#print('l\'url: ' + url + ' est invalide') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return urls_hs |
|
|
|
return urls_hs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FONCTION SEND MAIL |
|
|
|
# FONCTION SEND MAIL |
|
|
|
def send_mail(urls_hs): |
|
|
|
def send_mail(urls_hs): |
|
|
|
|
|
|
|
|
|
|
@ -46,7 +47,7 @@ def send_mail(urls_hs): |
|
|
|
if urls_hs: |
|
|
|
if urls_hs: |
|
|
|
for url in urls_hs: |
|
|
|
for url in urls_hs: |
|
|
|
mail = " ".join(urls_hs) |
|
|
|
mail = " ".join(urls_hs) |
|
|
|
contenu = '<h4>Bonjour, voici la liste des sites HS: {mail} <br></h4>\n'.format(mail=mail) |
|
|
|
contenu = '<h4>Bonjour, voici la liste du ou des sites HS: {mail} <br></h4>\n'.format(mail=mail) |
|
|
|
|
|
|
|
|
|
|
|
body = MIMEText(contenu, 'html') |
|
|
|
body = MIMEText(contenu, 'html') |
|
|
|
message.attach(body) |
|
|
|
message.attach(body) |
|
|
@ -62,16 +63,48 @@ def send_mail(urls_hs): |
|
|
|
mailReception, |
|
|
|
mailReception, |
|
|
|
mail_str) |
|
|
|
mail_str) |
|
|
|
server.quit() |
|
|
|
server.quit() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ALERTE = TRUE |
|
|
|
|
|
|
|
is_in_alert = True |
|
|
|
|
|
|
|
time_stamp = time.ctime() |
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
print('Tout est OK ;)') |
|
|
|
print('Tout est OK ;)') |
|
|
|
|
|
|
|
is_in_alert = False |
|
|
|
|
|
|
|
print(is_in_alert) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CHECK TIMER FONCTIONS |
|
|
|
|
|
|
|
def check_timer(time_stamp, current_time): |
|
|
|
|
|
|
|
if current_time - time_stamp > time_limit: |
|
|
|
|
|
|
|
print(current_time - time_stamp) |
|
|
|
|
|
|
|
resend = True |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
resend = False |
|
|
|
|
|
|
|
print(current_time - time_stamp) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resend |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FONCTION CHECK IF MAIL ALREADY SEND |
|
|
|
|
|
|
|
def check_alert(): |
|
|
|
|
|
|
|
if is_in_alert: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CHECK si timer > 1 heure |
|
|
|
|
|
|
|
resend = check_timer(time_stamp, time.ctime()) |
|
|
|
|
|
|
|
if resend: |
|
|
|
|
|
|
|
urls = test_url() |
|
|
|
|
|
|
|
send_mail(urls) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
urls = test_url() |
|
|
|
|
|
|
|
send_mail(urls) |
|
|
|
|
|
|
|
|
|
|
|
# MAIN (A) |
|
|
|
# MAIN (A) |
|
|
|
urls = import_url() |
|
|
|
check_alert() |
|
|
|
send_mail(urls) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# PYTHON TIME (B) |
|
|
|
# PYTHON TIME (B) |
|
|
|
# while True: |
|
|
|
# while True: |
|
|
|
# urls = import_url() |
|
|
|
# urls = test_url() |
|
|
|
# send_mail(urls) |
|
|
|
# send_mail(urls) |
|
|
|
|
|
|
|
|
|
|
|
# time.sleep(300) |
|
|
|
# time.sleep(300) |
|
|
|