def run(self):
        derniere_mise_a_jour = time.time()
        periode_mise_a_jour_gmail = 120
        six_jours = 518400
        trois_jours = 3*24*3600
        reinitialisation_gmail = time.time()
        #maintenant = 0 #permet d'envoyer un message de démarrage
        while True:

            maintenant = time.time()
            if distance_seconde(maintenant,derniere_mise_a_jour) > periode_mise_a_jour_gmail:
                print "on vérifie les courriels reçus"
                messages = self.gmail_lire.getMessagesList()
                if messages['messages']:
                    l_id = [msg['id'] for msg in messages['messages'] if not msg['id'] in self.l_id_courriels ]
                    for msg_id in l_id:
                        m = self.gmail_lire.getMessageDetails(msg_id)
                        if m.getFrom() in self.PROVENANCE_SURE:
                            self.rec.enregistrer_courriel(self, m.getFrom(), m.getTo(), m.getSubject(), m.getText(self.gmail_lire.gmail_service, 'me', msg_id))
                            if m.getSubject() == "ordre":
                                l_instructions = extraire_ordre(m.getText(self.gmail_lire.gmail_service,"*****@*****.**", msg_id))
                                # for instruction in l_instructions:
                                #     if instruction['categorie']
                                #     RecuperateurDonnees.obtenir_conditions_meteorologiques()
                            elif m.getSubject() == "questions":
                                l_instructions = extraire_question(m.getText(self.gmail_lire.gmail_service, "*****@*****.**", msg_id))
                            else:
                                pass
                            if m.getSubject() == "IP":
                                self.gmail_envoyer = Gmail(self.flags, client_secret_file =self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.send')
                                #ip = os.system("ifconfig")
                                message = Message(sender="*****@*****.**",to="*****@*****.**",subject="IP",
                                                 message_text= "faut m'extraire", service=self.gmail_envoyer.gmail_service)
                                message.sendMessage(self.gmail_envoyer.gmail_service, "*****@*****.**")
                                self.gmail_lire = Gmail(self.flags, client_secret_file =self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.readonly')


                derniere_mise_a_jour = maintenant
            elif distance_jour(maintenant, reinitialisation_gmail) > 6:
                print "on réinitialise la connexion"
                self.gmail_lire = Gmail(self.flags, client_secret_file = self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.readonly')
                self.gmail_envoyer = Gmail(self.flags, client_secret_file = self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.send')
                reinitialisation_gmail = maintenant
            elif distance_jour(maintenant, reinitialisation_gmail) > 3:
                print "on envoie un courriel à tout le monde"
                for destinataire in self.destinataires:

                    print self.rec.obtenir_conditions_meteorologiques()
                    #res = [(i.temperature,i.humidite_relative, i.date) for i in ConditionsMeteorologiques.objects.all() if datetime.timedelta.total_seconds(i.date - datetime.datetime.now())]
                    self.rec.obtenir_conditions_meteorologiques_depuis(3)
                    message = Message_Attachment(sender="*****@*****.**",to="*****@*****.**",subject="rapport météo",
                                                 message_text= "test", service=self.gmail_envoyer.gmail_service)
                    #message = Message_Attachment(sender="*****@*****.**",to=destinataire,subject="rapport météo",
                    #                             message_text= "test", file_dir=os.getcwd(), filename= "",
                    #                             service=gmail.gmail_service)
                    message.sendMessage(self.gmail_envoyer.gmail_service, "*****@*****.**")
 def __init__(self, json_file, PROVENANCE_SURE, DESTINATAIRES):
     print "on gère les courriels"
     threading.Thread.__init__(self)
     parser = argparse.ArgumentParser(parents=[argparser])
     self.flags = parser.parse_args()
     self.PROVENANCE_SURE = PROVENANCE_SURE
     self.json_file = json_file
     self.parser = argparse.ArgumentParser(parents=[argparser])
     self.gmail_lire = Gmail(self.flags, client_secret_file =self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.readonly')
     messages = self.gmail_lire.getMessagesList()
     if messages['messages']:
         self.l_id_courriels = [ msg['id'] for msg in messages['messages']]
         #= gmail.getMessageDetails(msg['id'])
     self.destinataires = DESTINATAIRES
     systeme = platform.system()
     self.rec = RecuperateurDonnees(os.getcwd())
     print "initialisation"
     self.gmail_envoyer = Gmail(self.flags, client_secret_file =self.json_file, oauth_scope = 'https://www.googleapis.com/auth/gmail.send')
     texte = """
             Bonjour\n\nLe service d'arrosage automatique a redémarré.\n\nCordialement\n\n Clément Besnier
             """
     message = Message(sender="*****@*****.**",to="*****@*****.**",subject="rapport météo",
                                              message_text= texte, service=self.gmail_envoyer.gmail_service)
                 #message = Message_Attachment(sender="*****@*****.**",to=destinataire,subject="rapport météo",
                 #                             message_text= "test", file_dir=os.getcwd(), filename= "",
                 #                             service=gmail.gmail_service)
     message.sendMessage(self.gmail_envoyer.gmail_service, "*****@*****.**")