MaoPost Python Gtk
by
xeo
@ 07/06/2007
Récupération du MaoPost du jour avec python-gtk
Cette application en PyGtk, permet de récupérer et d'afficher l'affiche MaoPost du jour.
#!/usr/bin/env python
import os
import time
import urllib2
import gtk
class appgui:
def destroy(self, w):
gtk.main_quit()
def __init__(self):
global maoLocalPic
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.image = gtk.Image()
self.window.add(self.image)
self.window.connect("destroy", self.destroy)
self.image.set_from_file(maoLocalPic)
self.image.show()
self.window.show()
def main(self):
gtk.main()
def download():
global maoLocalPic
if not os.path.exists( maoLocalPic ):
maoTxt = urllib2.urlopen("http://www.maopost.com/widget/widget.txt").read()
maoRemotePic = maoTxt.split()[0]
remoteFile = urllib2.urlopen(maoRemotePic)
localFile = open(maoLocalPic, "w")
localFile.write( remoteFile.read() )
remoteFile.close()
localFile.close()
if __name__ == '__main__' :
maoLocalPic = "/tmp/mao-" + time.strftime("%m-%d-%y", time.localtime()) + ".jpg"
download()
app=appgui()
app.main()
Par xeo
Dernière modification
07/06/2007 13:14