Bonne nouvelle j'ai trouvé deux trois bug qui permet de faire marcher mon petit programme python il a un seul prb le fichier xml généré est présque incompréhensible pour un humain.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys, xml.dom.minidom, urllib
from xml.dom.minidom import Document
from xml.dom import minidom
path = "/home/tyrus/background/"
lieu = 'FRXX0114'
meteoxml = urllib.urlopen('http://xoap.weather.com/weather/local/'+ lieu +'?cc=*&unit=m&dayf=2')
document = minidom.parse(meteoxml)
meteoxml.close()
# Récupération du temps
t = document.getElementsByTagName('cc')[0].getElementsByTagName('t')[0].childNodes[0].nodeValue
weather = t.encode('iso-8859-1')
lever = document.getElementsByTagName('loc')[0].getElementsByTagName('sunr')[0].childNodes[0].nodeValue
leverH = lever.split(":")[0]
leverM = lever.split(":")[1].split()[0]
coucher = document.getElementsByTagName('loc')[0].getElementsByTagName('suns')[0].childNodes[0].nodeValue
coucherH = str(int(coucher.split(":")[0]) + 12)
coucherM = coucher.split(":")[1].split()[0]
temps = {"Cloudy":"cloudy","Fair":"fair","Party Cloudy":"party_cloudy","Shower":"shower","Rain":"rain","Snow":"snow","Storm":"storm","Sunny":"sunny",'Mostly Cloudy':"cloudy"
}
doc = Document()
def creerNoeud(nom):
noeud = doc.createElement(nom)
return noeud
def creerN(pere,fils,valeur=""):
fils = creerNoeud(fils)
texte = doc.createTextNode(valeur)
fils.appendChild(texte)
pere.appendChild(fils)
# Create balise background
background = doc.createElement("background")
doc.appendChild(background)
# Create balise starttime
starttime = doc.createElement("starttime")
background.appendChild(starttime)
# Create noeud de startime
creerN(starttime,"year","2007")
creerN(starttime,"month","09")
creerN(starttime,"days","26")
creerN(starttime,"hour","07")
creerN(starttime,"minute","00")
creerN(starttime,"second","00")
def creerNStatic(durer,fichier):
static = doc.createElement("static")
background.appendChild(static)
creerN(static,"duration",durer)
creerN(static,"file",fichier)
def creerNTransition(durer,fichier1,fichier2,mode="overlay"):
transition = doc.createElement("transition")
transition.setAttribute("type", mode)
background.appendChild(transition)
creerN(transition,"duration",durer)
creerN(transition,"from",fichier1)
creerN(transition,"to",fichier2)
# We start with sunrise at 7 AM. It will remain up for 1 hour.
creerNStatic("3600", path + temps[weather] + "1.jpg")
# Sunrise starts to transition to day at 8 AM. The transition lasts for 5 hours, ending at 1 PM.
creerNTransition("18000",path + temps[weather] + "1.jpg",path + temps[weather] + "2.jpg")
#It's 1 PM, we're showing the day image in full force now, for 2 hours ending at 3 PM.
creerNStatic("7200", path + temps[weather] + "2.jpg")
# It's 3 PM, and we're starting to transition to sunset. Transition completes at 6 PM. -->
creerNTransition("10800",path + temps[weather] + "2.jpg",path +temps[weather] + "3.jpg")
# It's 6 PM, and it's sunset, for an hour. Ends at 7. -->
creerNStatic("3600", path + temps[weather] +"3.jpg")
#It's 7 PM and it's going to start to get darker. This will transition for 3 hours up until 10pm. -->
creerNTransition("10800",path + temps[weather] + "3.jpg",path + temps[weather] + "4.jpg")
# It's 10pm. It'll stay dark for 7 hours up until 5 AM. -->
creerNStatic("25200", path + temps[weather] + "4.jpg")
#It's 5 AM. We'll start transitioning to sunrise for 2 hours up until 7 AM. -->
creerNTransition("7200",path + temps[weather] + "4.jpg",path + temps[weather] + "1.jpg")
f = open('sortie.xml', 'w')
f.write(doc.toxml())
f.close()
Vous devez seulement modifié les 2 variable du début.
path = "/home/tyrus/background/" => emplacement des image sous la forme temps1.jpg
lieu = 'FRXX0114' => la ref de votre lien
Pour le lancer tous les 15 min vous pouvez faire mettre ce petit script (je regarde ça pour faire ça aussi en python )
#/bin/bash
sleep 15m
python /home/tyrus/Dev/background.py