# -*- coding: utf-8 -*-
"""
Éditeur de Spyder

Ce script temporaire est sauvegardé ici :
C:\Users\hugo\.spyder2\.temp.py
"""

##### Bibliothéque

import urllib  
import time
from datetime import datetime

##### Liste des URLs contenant les HTML Ouvert-Lu-Fermé
                                 
sock = urllib.urlopen("http://fr.weather.com/conditions_actuelles/Maul%C3%A9vrier-Sainte-Gertrude+76+France+FRHN0560:1:FR") 
htmlSource = sock.readlines()                            
sock.close()

sock2 = urllib.urlopen("http://fr.weather.com/10jours/FRHN0560:1:FR")
htmlSource2 = sock2.readlines()
sock2.close()

sock3 = urllib.urlopen("http://vfph.fr/meteo/")
site = sock3.readlines()
sock3.close()

URL1_lecture=urllib.urlopen("http://fr.weather.com/horaire/FRHN0560:1:FR?pagenum=1&nextbeginIndex=0")
URL1=URL1_lecture.readlines()
URL1_lecture.close()

URL2_lecture=urllib.urlopen("http://fr.weather.com/horaire/FRHN0560:1:FR?pagenum=2&nextbeginIndex=6")
URL2=URL2_lecture.readlines()
URL2_lecture.close()

URL3_lecture=urllib.urlopen("http://fr.weather.com/horaire/FRHN0560:1:FR?pagenum=3&nextbeginIndex=18")
URL3=URL3_lecture.readlines()
URL3_lecture.close()

URL4_lecture=urllib.urlopen("http://fr.weather.com/horaire/FRHN0560:1:FR?pagenum=4&nextbeginIndex=30")
URL4=URL4_lecture.readlines()
URL4_lecture.close()        

URL5_lecture=urllib.urlopen("http://fr.weather.com/horaire/FRHN0560:1:FR?pagenum=5&nextbeginIndex=42")
URL5=URL5_lecture.readlines()
URL5_lecture.close()  

URL_liste=[URL1],[URL2],[URL3],[URL4],[URL5]


######################################################################################
######################################################################################
######################################################################################

### variable heure/journé

heure=datetime.now().hour
journee=datetime.now().day

#### CODE Initiale-modifié 

CODE = ['\n', '<html>\n', '<head>\n', '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">\n', '<title>METEO fpo (BETA) </title>\n', '</head>\n', '<body>\n', '<FONT face="Comic Sans MS" color="#336699" size="1">\n', '<div id="table_content">\n', '<table border bgcolor="#FFFF66" cellpadding="0" cellspacing="0" width="480" id="hourbyhour_table">\n', '<FONT face="Comic Sans MS" color="#336699" size="1">\n', '<tr>\n', '  <th>Heure</th>\n', '  <th>Temp\xc3\xa9rature</th>\n', '  <th colspan="2">Conditions</th>\n', '  <th>Risque de pr\xc3\xa9cip.</th>\n', '  <th colspan="2">Vent</th>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" bgcolor="#C0C0C0" size="1">\n', '  <td colspan="7" class="hourly_divider" style="color:#ffffff;padding-bottom:7px;" bgcolor="#C0C0C0">\n', '    <center>\n', '      <strong>Samedi \n', '15\n', ' D\xc3\xa9cembre </strong>\n', '    </center>\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>09:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 7&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/28.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Tr\xc3\xa8s nuageux\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    10%\r\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SSO.gif"\n', '     alt="">\n', '    27 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>12:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 8&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/28.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Tr\xc3\xa8s nuageux\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    20%\r\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SSO.gif"\n', '     alt="">\n', '    27 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>15:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 9&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/26.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Nuageux\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    20%\r\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SSO.gif"\n', '     alt="">\n', '    26 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>18:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 8&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/11.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Quelques averses\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    30%\r\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SO.gif"\n', '     alt="">\n', '    24 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" bgcolor="#C0C0C0" size="1">\n', '  <td colspan="7" class="hourly_divider" style="color:#ffffff;padding-bottom:7px;" bgcolor="#C0C0C0">\n', '    <center>\n', '      <strong>Dimanche \n', '16\n', ' D\xc3\xa9cembre </strong>\n', '    </center>\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>09:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t6&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/28.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Tr\xc3\xa8s nuageux\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    20%\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SO.gif"\n', '     alt="">\n', '    \t\t\t\t\t\t\t\t\t\t\t\t26 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>15:00</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t 8&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/28.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    Tr\xc3\xa8s nuageux\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    20%\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SO.gif"\n', '     alt="">\n', '    \t\t\t\t\t\t\t\t\t\t\t\t26 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" bgcolor="#C0C0C0" size="1">\n', '  <td colspan="7" class="hourly_divider" style="color:#ffffff;padding-bottom:7px;" bgcolor="#C0C0C0">\n', '    <center>\n', '      <strong>Lundi \n', '17\n', ' D\xc3\xa9cembre </strong>\n', '    </center>\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>Jour</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 8&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/39.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', "    \t\t\t\t\t\t\t\tAverses dans l'apr\xc3\xa8s-midi\r\n", '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    30%\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SO.gif"\n', '     alt="">\n', '    \t\t\t\t\t\t\t\t\t\t\t\t26 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" bgcolor="#C0C0C0" size="1">\n', '  <td colspan="7" class="hourly_divider" style="color:#ffffff;padding-bottom:7px;" bgcolor="#C0C0C0">\n', '    <center>\n', '      <strong>Mardi \n', '18\n', ' D\xc3\xa9cembre </strong>\n', '    </center>\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>Jour</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 7&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/11.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    \t\t\t\t\t\t\t\tAverses\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    60%\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/NNO.gif"\n', '     alt="">\n', '    \t\t\t\t\t\t\t\t\t\t\t\t23 km/h\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" bgcolor="#C0C0C0" size="1">\n', '  <td colspan="7" class="hourly_divider" style="color:#ffffff;padding-bottom:7px;" bgcolor="#C0C0C0">\n', '    <center>\n', '      <strong>Mercredi \n', '19\n', ' D\xc3\xa9cembre </strong>\n', '    </center>\n', '  </td>\n', '</tr>\n', '<tr>\n', '  <FONT face="Comic Sans MS" color="#000000" size="1">\n', '  <td width="62" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 10px; font-weight: bold;">\n', '      <strong>Jour</strong>\n', '    </span>\n', '  </td>\n', '  <td width="91" align="center" style="padding-top:12px;" bgcolor="#FFFFFF">\n', '    <span style="font-size: 17px; font-weight: bold;"> 6&deg;C\n', '    </span>\n', '  </td>\n', '  <td width="48" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/26.png"\n', '    width="31" height="31" alt="">\n', '  </td>\n', '  <td width="141" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    \t\t\t\t\t\t\t\tNuageux\r\n', '  </td>\n', '  <td width="82" align="center" style="padding-top:14px;" bgcolor="#FFFFFF">\n', '    20%\n', '  </td>\n', '  <td width="100" align="center" style="border-right: none;" bgcolor="#FFFFFF"><img class="transparent" align="center"\n', '    src="./images/SE.gif"\n', '     alt="">\n', '    \t\t\t\t\t\t\t\t\t\t\t\t24 km/h\n', '  </td>\n', '</tr>\n', '</body>\n', '</html>\n']


### Fonction pour trouver X : (interet : recaller le programme sur les bonnes lignes en cas de rajout/supression de ligne)


for k in range (200,220):
    if ((htmlSource2)[k]=='</div>\n'):
        x=210-(k) + 1
        
############################




def recherche_aujourdhui(X):
    ### délimité la recherche ici on trouve la limite superieur
    URL=URL_liste[0][0]
    k=0
    i=0
    while(URL[k]!=('<span class="wx-label">'+journee_demain[0:3]+'.</span>\n')):
       k+=1
       if k == (len(URL)-1) and i<4:
          k=0
          i+=1
          URL=URL_liste[i][0]
    fin = [k,i]
    ### la lilimite inferieur 
    URL=URL_liste[0][0]
    k=0
    i=0
    while(URL[k]!=('<span class="wx-label">'+journee_aujourdhui[0:3]+'.</span>\n')):
       k+=1
       if k == (len(URL)-1) and i<4:
          k=0
          i+=1
          URL=URL_liste[i][0]
    debut = [k-10,i]
    while(URL[k]!=('<h3 class="wx-time">'+X+'\n')):
        k+=1
        if k == (len(URL)-1) and i<4:
            k=0
            i+=1
            URL=URL_liste[i][0]
        if i==4 and k == (len(URL)-1):
            liste_local=['./image/25.png',"--",'non communiqué','--','--','25']
            return liste_local    
    if (i==debut[1] and debut[0]<k) or (debut[1]<i<fin[1]) or (i==fin[1] and fin[0]>k) :      
            if (190<k<210):
                r=1
            else:
                r=0
            FIXE=k+r    
            
            image_local=''
            k=10
            while((URL)[FIXE+3][k]!='"'):
               image_local+=(URL)[FIXE+3][k]
               k+=1
               
            temperature_local=''
            k=0
            while((URL)[FIXE+5][k]!='<'):
               temperature_local+=(URL)[FIXE+5][k]
               k+=1
               
            etat_local=''
            k=21
            while((URL)[FIXE+7][k]!='<'):
               etat_local+=(URL)[FIXE+7][k]
               k+=1
            
            probabilite_local=''
            k=0
            while((URL[FIXE+25])[k]!='&'):
                probabilite_local+=(URL)[FIXE+25][k]
                k+=1
                
            vitesse_local=''
            compte=len((URL)[FIXE+30])-1
            k=11
            while((URL)[FIXE+30][compte-k]!=' '):
                vitesse_local+=(URL)[FIXE+30][compte-k]
                k+=1
            vitesse_local=vitesse_local[::-1]   
            
            direction_local=''
            k=4
            while((URL)[FIXE+30][k]!=' '):
                 direction_local+=(URL)[FIXE+30][k]
                 k+=1
            
            liste_local=[image_local,temperature_local,etat_local,probabilite_local,vitesse_local,direction_local]
            return liste_local
    else :
        return ['./image/25.png',"--",'non communiqué','--','--','25']
          
    
    
def fin_demain():
    URL=URL_liste[0][0]
    k=0
    i=0
    while(URL[k]!=('<span class="wx-label">'+journee_deuxjour[0:3]+'.</span>\n')):
       k+=1
       if k == (len(URL)-1) and i<4:
          k=0
          i+=1
          URL=URL_liste[i][0]
       if k == (len(URL)-1) and i==4:
          return [500,4]
    return [k,i]      
       
    
    


def recherche_demain(X):
    
    fin=fin_demain()
    URL=URL_liste[0][0]
    k=0
    i=0
    while(URL[k]!=('<span class="wx-label">'+journee_demain[0:3]+'.</span>\n')):
       k+=1
       if k == (len(URL)-1) and i<4:
          k=0
          i+=1
          URL=URL_liste[i][0]
    debut = [k-10,i]
    k+=1
    while(URL[k]!=('<h3 class="wx-time">'+X+'\n')):
        k+=1
        if k == (len(URL)-1) and i<4:
            k=0
            i+=1
            URL=URL_liste[i][0]
        if i==4 and k == (len(URL)-1):
            liste_local=['./image/25.png',"--",'non communiqué','--','--','25']
            return liste_local      
    if (i==debut[1] and debut[0]<k) or (debut[1]<i<fin[1]) or (i==fin[1] and fin[0]>k):
        
            if (190<k<210):
                r=1
            else:
                r=0
            FIXE=k+r    
            
            image_local=''
            k=10
            while((URL)[FIXE+3][k]!='"'):
               image_local+=(URL)[FIXE+3][k]
               k+=1
               
            temperature_local=''
            k=0
            while((URL)[FIXE+5][k]!='<'):
               temperature_local+=(URL)[FIXE+5][k]
               k+=1
               
            etat_local=''
            k=21
            while((URL)[FIXE+7][k]!='<'):
               etat_local+=(URL)[FIXE+7][k]
               k+=1
            
            probabilite_local=''
            k=0
            while((URL[FIXE+25])[k]!='&'):
                probabilite_local+=(URL)[FIXE+25][k]
                k+=1
                
            vitesse_local=''
            compte=len((URL)[FIXE+30])-1
            k=11
            while((URL)[FIXE+30][compte-k]!=' '):
                vitesse_local+=(URL)[FIXE+30][compte-k]
                k+=1
            vitesse_local=vitesse_local[::-1]   
            
            direction_local=''
            k=4
            while((URL)[FIXE+30][k]!=' '):
                 direction_local+=(URL)[FIXE+30][k]
                 k+=1
            
            liste_local=[image_local,temperature_local,etat_local,probabilite_local,vitesse_local,direction_local]
            return liste_local
    else :
        return ['./image/25.png',"--",'non communiqué','--','--','25']
         




#### ASSOCIATION IMAGE/URL 

    
def url_direction(X):
    image='./image/'+X+'.gif'
    return image     


################################################
####  Associer date/journée de la semaine ######
################################################

analyse=time.localtime()[6] 

### analyse=time.localtime()[0] = lundi !!!! 

if analyse==0:
    journee_aujourdhui='lundi'
    journee_demain='mardi'
    journee_deuxjour='mercredi'
    journee_troisjour='jeudi'
    journee_quatrejour='vendredi'

elif analyse==1:
    journee_aujourdhui='mardi'
    journee_demain='mercredi'
    journee_deuxjour='jeudi'
    journee_troisjour='vendredi'
    journee_quatrejour='samedi'
    
    
elif analyse==2:
    journee_aujourdhui='mercredi'
    journee_demain='jeudi'
    journee_deuxjour='vendredi'
    journee_troisjour='samedi'
    journee_quatrejour='dimanche'
    
elif analyse==3:
    journee_aujourdhui='jeudi'
    journee_demain='vendredi'
    journee_deuxjour='samedi'
    journee_troisjour='dimanche'    
    journee_quatrejour='lundi'
    
elif analyse==4:
    journee_aujourdhui='venderdi'
    journee_demain='samedi'
    journee_deuxjour='dimanche'
    journee_troisjour='lundi'  
    journee_quatrejour='mardi'

elif analyse==5:
    journee_aujourdhui='samedi'
    journee_demain='dimanche'
    journee_deuxjour='lundi'
    journee_troisjour='mardi'  
    journee_quatrejour='mercredi'

elif analyse==6:
    journee_aujourdhui='dimanche'
    journee_demain='lundi'
    journee_deuxjour='mardi'
    journee_troisjour='mercredi'    
    journee_quatrejour='jeudi'     
    




def change_mois(x):

    if x == 'janv':
        mois ='janvier'
        return 
    elif (x == 'juil'):
        mois='juillet'
        return mois   
    elif (x == 'aout'):
        mois='aout' 
        return mois 
    elif (x == 'sept'):
        mois='septembre'
        return mois
    elif (x == 'octo'):
        mois='octobre'
        return mois
    elif (x == 'nove'):
        mois='novembre'
        return mois
    elif (x == 'dece'):
        mois='decembre'
        return mois
    elif (x == 'fevr'):
        mois='fevrier'
        return mois
    elif (x == 'mars'):
        mois='mars'
        return mois
    elif (x == 'avri'):
        mois='avril'
        return mois
    elif (x  == 'mai'):
        mois='mai'
        return mois
    elif (x == 'juin'):
        mois='juin'
        return mois
    



##################################################################
#####################  AUJOURD'HUI ###############################
##################################################################



aujourdhui=''
k=23
while((htmlSource2)[198][k]!='<'):
     aujourdhui+=(htmlSource2)[198][k]
     k+=1

aujourdhui_9000 = recherche_aujourdhui('0900')
aujourdhui_1200 = recherche_aujourdhui('1200')
aujourdhui_1500 = recherche_aujourdhui('1500')
aujourdhui_1800 = recherche_aujourdhui('1800')

demain_1500=recherche_demain('1500')
demain_9000=recherche_demain('0900')



#################################################################
####################  DEMAIN ####################################
#################################################################

demain=''
k=23
while((htmlSource2)[280-x][k]!='<'):
     demain+=(htmlSource2)[280-x][k]
     k+=1


temperature_demain=''
k=0
while((htmlSource2)[285-x][k]!='<'):
     temperature_demain+=(htmlSource2)[285-x][k]
     k+=1


etat_demain=''
k=21
while((htmlSource2)[290-x][k]!='<'):
     etat_demain+=(htmlSource2)[290-x][k]
     k+=1
   

vitesse_demain=''
compte=len((htmlSource2)[300-x])-1
k=6
while((htmlSource2)[300-x][compte-k]!=' '):
    vitesse_demain+=(htmlSource2)[300-x][compte-k]
    k+=1
vitesse_demain=vitesse_demain[::-1]


humidite_demain=''
k=4
while((htmlSource2)[306-x][k]!='%'):
     humidite_demain+=(htmlSource2)[306-x][k]
     k+=1



direction_demain=''
k=0
while((htmlSource2)[300-x][k]!=' '):
     direction_demain+=(htmlSource2)[300-x][k]
     k+=1


probabilite_demain=''
k=4
while ((htmlSource2)[295-x][k]!='%'):
    probabilite_demain+=(htmlSource2)[295-x][k]
    k+=1




#################################################################
####################  JOUR 2 ####################################
#################################################################


deuxjour=''
k=23
while((htmlSource2)[360-x][k]!='<'):
     deuxjour+=(htmlSource2)[360-x][k]
     k+=1


temperature_deuxjour=''
k=0
while((htmlSource2)[365-x][k]!='<'):
     temperature_deuxjour+=(htmlSource2)[365-x][k]
     k+=1
  


etat_deuxjour=''
k=21
while((htmlSource2)[370-x][k]!='<'):
     etat_deuxjour+=(htmlSource2)[370-x][k]
     k+=1


vitesse_deuxjour=''
compte=len((htmlSource2)[380-x])-1
k=6
while((htmlSource2)[380-x][compte-k]!=' '):
    vitesse_deuxjour+=(htmlSource2)[380-x][compte-k]
    k+=1
vitesse_troisjour=vitesse_deuxjour [::-1]


humidite_deuxjour=''
k=4
while((htmlSource2)[386-x][k]!='%'):
     humidite_deuxjour+=(htmlSource2)[386-x][k]
     k+=1



direction_deuxjour=''
k=0
while((htmlSource2)[380-x][k]!=' '):
     direction_deuxjour+=(htmlSource2)[380-x][k]
     k+=1


probabilite_deuxjour=''
k=4
while ((htmlSource2)[375-x][k]!='%'):
    probabilite_deuxjour+=(htmlSource2)[375-x][k]
    k+=1


image_deuxjour=''
k=10
while((htmlSource2)[363-x][k]!='"'):
    image_deuxjour+=(htmlSource2)[363-x][k]
    k+=1





#################################################################
####################  JOUR 3 ####################################
#################################################################


troisjour=''
k=23
while((htmlSource2)[440-x][k]!='<'):
     troisjour+=(htmlSource2)[440-x][k]
     k+=1


temperature_troisjour=''
k=0
while((htmlSource2)[445-x][k]!='<'):
     temperature_troisjour+=(htmlSource2)[445-x][k]
     k+=1
    


etat_troisjour=''
k=21
while((htmlSource2)[450-x][k]!='<'):
     etat_troisjour+=(htmlSource2)[450-x][k]
     k+=1
  


vitesse_troisjour=''
compte=len((htmlSource2)[460-x])-1
k=6
while((htmlSource2)[460-x][compte-k]!=' '):
    vitesse_troisjour+=(htmlSource2)[460-x][compte-k]
    k+=1
vitesse_troisjour= vitesse_troisjour [::-1]


humidite_troisjour=''
k=4
while((htmlSource2)[466-x][k]!='%'):
     humidite_troisjour+=(htmlSource2)[466-x][k]
     k+=1



direction_troisjour=''
k=0
while((htmlSource2)[460-x][k]!=' '):
     direction_troisjour+=(htmlSource2)[460-x][k]
     k+=1


probabilite_troisjour=''
k=4
while ((htmlSource2)[455-x][k]!='%'):
    probabilite_troisjour+=(htmlSource2)[455-x][k]
    k+=1



image_troisjour=''
k=10
while((htmlSource2)[443-x][k]!='"'):
    image_troisjour+=(htmlSource2)[443-x][k]
    k+=1




#################################################################
####################  JOUR 4 ####################################
#################################################################

quatrejour=''
k=23
while((htmlSource2)[440-x+80][k]!='<'):
     quatrejour+=(htmlSource2)[440-x+80][k]
     k+=1


temperature_quatrejour=''
k=0
while((htmlSource2)[445-x+80][k]!='<'):
     temperature_quatrejour+=(htmlSource2)[445-x+80][k]
     k+=1
    


etat_quatrejour=''
k=21
while((htmlSource2)[450-x+80][k]!='<'):
     etat_quatrejour+=(htmlSource2)[450-x+80][k]
     k+=1
  


vitesse_quatrejour=''
compte=len((htmlSource2)[460-x+80])-1
k=6
while((htmlSource2)[460-x+80][compte-k]!=' '):
    vitesse_quatrejour+=(htmlSource2)[460-x+80][compte-k]
    k+=1
vitesse_quatrejour= vitesse_quatrejour [::-1]


humidite_quatrejour=''
k=4
while((htmlSource2)[466-x+80][k]!='%'):
     humidite_quatrejour+=(htmlSource2)[466-x+80][k]
     k+=1



direction_quatrejour=''
k=0
while((htmlSource2)[460-x+80][k]!=' '):
     direction_quatrejour+=(htmlSource2)[460-x+80][k]
     k+=1


probabilite_quatrejour=''
k=4
while ((htmlSource2)[455-x+80][k]!='%'):
    probabilite_quatrejour+=(htmlSource2)[455-x+80][k]
    k+=1



image_quatrejour=''
k=10
while((htmlSource2)[443-x+80][k]!='"'):
    image_quatrejour+=(htmlSource2)[443-x+80][k]
    k+=1





#################################################################
####################  REMPLACEMENT ##############################
#################################################################



mois_demain = change_mois(demain[4:(len(demain)-1)])
mois_aujourdhui = change_mois(aujourdhui[4:(len(aujourdhui)-1)])
mois_deuxjour = change_mois(deuxjour[4:(len(deuxjour)-1)])
mois_troisjour = change_mois(troisjour[4:(len(troisjour)-1)])
mois_quatrejour = change_mois(quatrejour[4:(len(quatrejour)-1)])





#### AUJOURDHUI ####

CODE[22]='      <strong>'+journee_aujourdhui+' \n'
CODE[23]=aujourdhui[0:2]+'\n'
CODE[24]=' '+mois_aujourdhui+'</strong>\n'

#### 9000 ####

CODE[36]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+aujourdhui_9000[1]+'&deg;C\n'
CODE[40]='    src="'+aujourdhui_9000[0]+'"\n'
CODE[44]='    '+aujourdhui_9000[2]+'\r\n'
CODE[47]='    '+aujourdhui_9000[3]+'%\n'
CODE[50]='    src="'+url_direction(aujourdhui_9000[5])+'"\n'
CODE[52]='    \t\t\t\t\t\t\t\t\t\t\t\t'+aujourdhui_9000[4]+' km/h\n'

#### 1200 ####

CODE[36+27]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+aujourdhui_1200[1]+'&deg;C\n'
CODE[40+27]='    src="'+aujourdhui_1200[0]+'"\n'
CODE[44+27]="    "+aujourdhui_1200[2]+'\r\n'
CODE[47+27]='    '+aujourdhui_1200[3]+'%\n'
CODE[50+27]='    src="'+url_direction(aujourdhui_1200[5])+'"\n'
CODE[52+27]='    \t\t\t\t\t\t\t\t\t\t\t\t'+aujourdhui_1200[4]+' km/h\n'

#### 1500 ####

CODE[36+54]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+aujourdhui_1500[1]+'&deg;C\n'
CODE[40+54]='    src="'+aujourdhui_1500[0]+'"\n'
CODE[44+54]="    "+aujourdhui_1500[2]+'\r\n'
CODE[47+54]='    '+aujourdhui_1500[3]+'%\n'
CODE[50+54]='    src="'+url_direction(aujourdhui_1500[5])+'"\n'
CODE[52+54]='    \t\t\t\t\t\t\t\t\t\t\t\t'+aujourdhui_1500[4]+' km/h\n'

#### 1800 #####

CODE[36+81]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+aujourdhui_1800[1]+'&deg;C\n'
CODE[40+81]='    src="'+aujourdhui_1800[0]+'"\n'
CODE[44+81]="    "+aujourdhui_1800[2]+'\r\n'
CODE[47+81]='    '+aujourdhui_1800[3]+'%\n'
CODE[50+81]='    src="'+url_direction(aujourdhui_1800[5])+'"\n'
CODE[52+81]='    \t\t\t\t\t\t\t\t\t\t\t\t'+aujourdhui_1800[4]+' km/h\n'







#### DEMAIN ####


CODE[140]='      <strong>'+journee_demain+' \n'
CODE[141]=demain[0:2]+'\n'
CODE[142]=' '+mois_demain+'</strong>\n'

### 9000 ###

CODE[154]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+demain_9000[1]+'&deg;C\n'
CODE[158]='    src="'+demain_9000[0]+'"\n'
CODE[162]='    '+demain_9000[2]+'\r\n'
CODE[165]='    '+demain_9000[3]+'%\n'
CODE[168]='    src="'+url_direction(demain_9000[5])+'"\n'
CODE[170]='    \t\t\t\t\t\t\t\t\t\t\t\t'+demain_9000[4]+' km/h\n'

#### 1500 #####

CODE[154+27]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+demain_1500[1]+'&deg;C\n'
CODE[158+27]='    src="'+demain_1500[0]+'"\n'
CODE[162+27]='    '+demain_1500[2]+'\r\n'
CODE[165+27]='    '+demain_1500[3]+'%\n'
CODE[168+27]='    src="'+url_direction(demain_1500[5])+'"\n'
CODE[170+27]='    \t\t\t\t\t\t\t\t\t\t\t\t'+demain_1500[4]+' km/h\n'





       

#### deuxjour ####

CODE[204]='      <strong>'+journee_deuxjour+' \n'
CODE[205]=deuxjour[0:2]+'\n'
CODE[206]=' '+mois_deuxjour+'</strong>\n'
CODE[218]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+temperature_deuxjour+'&deg;C\n'
CODE[222]='    src="'+image_deuxjour+'"\n'
CODE[226]="    \t\t\t\t\t\t\t\t"+etat_deuxjour+'\r\n'
CODE[229]='    '+probabilite_deuxjour+'%\n'
CODE[232]='    src="'+url_direction(direction_deuxjour)+'"\n'
CODE[234]='    \t\t\t\t\t\t\t\t\t\t\t\t'+vitesse_deuxjour+' km/h\n'



#### troisjour ####

CODE[204+37]='      <strong>'+journee_troisjour+' \n'
CODE[205+37]=troisjour[0:2]+'\n'
CODE[206+37]=' '+mois_troisjour+'</strong>\n'
CODE[218+37]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+temperature_troisjour+'&deg;C\n'
CODE[222+37]='    src="'+image_troisjour+'"\n'
CODE[226+37]="    \t\t\t\t\t\t\t\t "+etat_troisjour+'\r\n'
CODE[229+37]='    '+probabilite_troisjour+'%\n'
CODE[232+37]='    src="'+url_direction(direction_troisjour)+'"\n'
CODE[234+37]='    \t\t\t\t\t\t\t\t\t\t\t\t'+vitesse_troisjour+' km/h\n'



#### quatrejour ####

CODE[204+74]='      <strong>'+journee_quatrejour+' \n'
CODE[205+74]=quatrejour[0:2]+'\n'
CODE[206+74]=' '+mois_quatrejour+'</strong>\n'
CODE[218+74]='    <span style="font-size: 17px; font-weight: bold;"> \t\t\t\t\t\t\t\t\t'+temperature_quatrejour+'&deg;C\n'
CODE[222+74]='    src="'+image_quatrejour+'"\n'
CODE[226+74]="    \t\t\t\t\t\t\t\t "+etat_quatrejour+'\r\n'
CODE[229+74]='    '+probabilite_quatrejour+'%\n'
CODE[232+74]='    src="'+url_direction(direction_quatrejour)+'"\n'
CODE[234+74]='    \t\t\t\t\t\t\t\t\t\t\t\t'+vitesse_quatrejour+' km/h\n'




       
       
#################################################################
####################  ECRITURE DU CODE HTML #####################
#################################################################
        
fichier=open("meteo.html","w") 
for k in range (len(CODE)):
 fichier.write(CODE[k])
fichier.close()    


    
    