AnsuzPeorth a écritJ'aurais dans l'idée d'adapter la taille de l'image
à la taille du bureau, et éventuellement d'ajouter en incrustation des infos
sur l'auteur de la photo. (nom ou pseudo)
C'est possible avec PIL, je dois avoir un exemple de ce genre; en cherchant bien :/
Dingue ce flickr !
Je connais pas cette API, mais il doit être très configurable, donc surement trier par taille voulu. Et puis ça évitera de parser du html ! Le retour en json est un plaisir à travailler.
Je sens que je vais en apprendre pas mal en bidouillant mon petit script
C'était pas le but :rolleyes: ?
Y a toujours un peu de ça, oui, quand même.
Franchement, on aurait eu ce langage à la fac au lieu de ce @!"#??#@ de Eiffel ...
Allez, voici la nouvelle version :
#!/usr/bin/python
import urllib2,random,time,datetime
import string,subprocess,re,os
opener = urllib2.build_opener()
# --- code issu du site : http://stackoverflow.com/questions/553303/generate-a-random-date-between-two-other-dates
def strTimeProp(start, end, format, prop):
stime = time.mktime(time.strptime(start, format))
etime = time.mktime(time.strptime(end, format))
ptime = stime + prop * (etime - stime)
return time.strftime(format, time.localtime(ptime))
def randomDate(start, end, prop):
return strTimeProp(start, end, '%Y/%m/%d', prop)
# --- fin du code
reLien = re.compile("<a href=[^>]*>")
rePhoto = re.compile("""\"/photos/[^\"^/]*/[^\"^/]*/\"""")
reUrl1 = re.compile("""url: \'.*_b.jpg'""")
reUrl2 = re.compile("""url: \'.*_z.jpg'""")
reUrl3 = re.compile("""url: \'[^_]*.jpg'""")
page = opener.open("http://www.flickr.com/explore/interesting/%s/page%02i/" % (randomDate("2004/07/01", "2011/06/16", random.random()),int(random.random()*50+1)))
html = page.read()
page.close()
photos=rePhoto.findall(html)
index=random.randint(1, len(photos))
page=opener.open("http://www.flickr.com%s" % (photos[index][1:len(photos[index])-1]))
html=page.read()
adrPhoto=reUrl1.findall(html)
print adrPhoto
if len(adrPhoto) == 0 :
adrPhoto=reUrl2.findall(html)
print adrPhoto
if len(adrPhoto) == 0 :
adrPhoto=reUrl3.findall(html)
print adrPhoto
adrPhoto=adrPhoto[0][6:-1]
page = opener.open(adrPhoto)
my_picture = page.read()
page.close()
filename = "%s/.tmpPhoto.jpg" % (os.path.expanduser("~") )
fout = open(filename, "wb")
fout.write(my_picture)
fout.close()
subprocess.Popen(args=["gconftool-2","--type","string","--set","/desktop/gnome/background/picture_filename",filename])
Alors , au programme :
Suppression de la dépendance curl
Suppression de la commande dépréciée commands et remplacement par subprocess
Correction d'un problème lié à la présence ou nom de formats d'image "_z" ou "_b"
Maintenant, reste plus qu'à affiner la présentation de la photo sur le bureau et à placer une icone dans la zone de notification
pour éventuellement mettre la photo de côté puisqu'elle est écrasée à chaque fois.