|
|
|
@ -7,8 +7,11 @@ from email.mime.multipart import MIMEMultipart |
|
|
|
|
from email.mime.text import MIMEText |
|
|
|
|
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 |
|
|
|
|
def import_url(): |
|
|
|
|
def test_url(): |
|
|
|
|
|
|
|
|
|
print(time.ctime()) |
|
|
|
|
urls_hs = [] |
|
|
|
@ -25,13 +28,11 @@ def import_url(): |
|
|
|
|
else: |
|
|
|
|
print(url + ' / ' + str(response.status_code)) |
|
|
|
|
except Exception as e: |
|
|
|
|
urls_hs.append(url) |
|
|
|
|
print(str(e)) |
|
|
|
|
#except: |
|
|
|
|
#print('l\'url: ' + url + ' est invalide') |
|
|
|
|
|
|
|
|
|
return urls_hs |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FONCTION SEND MAIL |
|
|
|
|
def send_mail(urls_hs): |
|
|
|
|
|
|
|
|
@ -46,7 +47,7 @@ def send_mail(urls_hs): |
|
|
|
|
if urls_hs: |
|
|
|
|
for url in 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') |
|
|
|
|
message.attach(body) |
|
|
|
@ -62,16 +63,48 @@ def send_mail(urls_hs): |
|
|
|
|
mailReception, |
|
|
|
|
mail_str) |
|
|
|
|
server.quit() |
|
|
|
|
|
|
|
|
|
# ALERTE = TRUE |
|
|
|
|
is_in_alert = True |
|
|
|
|
time_stamp = time.ctime() |
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
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) |
|
|
|
|
urls = import_url() |
|
|
|
|
send_mail(urls) |
|
|
|
|
check_alert() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# PYTHON TIME (B) |
|
|
|
|
# while True: |
|
|
|
|
# urls = import_url() |
|
|
|
|
# urls = test_url() |
|
|
|
|
# send_mail(urls) |
|
|
|
|
|
|
|
|
|
# time.sleep(300) |
|
|
|
|