Programme a la télé ce soir

Description

Bonjour,

alors ce code est très simple,

le script se connecte sur un site de programme télé et affiche le programme télé .heure, programe, résumé...
le script prend en compte les chaines TF1,FRANCE2,FRANCE3,RTL,PLUG,....
on peux en rajouter très facilement en modifiant le dictionnaire avec les chaines définie

Source / Exemple :


# fenetre.py
#################################################
# Monoyer Fabian : Chaine television              
# License: GPL                              
#################################################
# -*- coding: utf-8 -*-

from qt import *

class Fenetre(QMainWindow):
    def __init__(self,parent = None,name = None,fl = 0):
        QMainWindow.__init__(self,parent,name,fl)
        self.statusBar()

        if not name:
            self.setName("Fenetre")

        self.setCentralWidget(QWidget(self,"qt_central_widget"))
        FenetreLayout = QGridLayout(self.centralWidget(),1,1,11,6,"FenetreLayout")

        self.splitter2 = QSplitter(self.centralWidget(),"splitter2")
        self.splitter2.setOrientation(QSplitter.Horizontal)

        self.listBox = QListBox(self.splitter2,"listBox")

        self.text = QTextEdit(self.splitter2,"text")
        self.text.setReadOnly(1)

        FenetreLayout.addWidget(self.splitter2,0,0)

        self.languageChange()

        self.resize(QSize(800,600).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.setTabOrder(self.listBox,self.text)

    def languageChange(self):
        self.setCaption(self.__trUtf8("\x50\x72\x6f\x67\x72\x61\x6d\x6d\x65\x20\x74\xc3\xa9\x6c\xc3\xa9"))

    def __trUtf8(self,s,c = None):
        return qApp.translate("Fenetre",s,c,QApplication.UnicodeUTF8)

#! /usr/bin/pytgon
# chainetv.py
#################################################
# Monoyer Fabian : Chaine television              
# python@euphonynet.be                          
# License: GPL                              
#################################################
# -*- coding: utf-8 -*-

import urllib2
import sys as Sys
from datetime import date
import fenetre as windows
import qt as Qt

def dateok(x):
    date1="%s/%s"%(date.today().day,date.today().month)
    date2="%s/%s"%(date.today().day+1,date.today().month)	
    days=dict([(1,31),(2,28),(3,31),(4,30),(5,31),(6,30),(7,31),(8,31),(9,30),(10,31),(11,30),(12,31)])
    if date.today().day==days[date.today().month] :
         day=1
         month=date.today().month()+1
         if month==13:
              month=1
         date2="%s/%s"%(day,month)
    if x==1 :
         return date1
    return date2

def openChan(chanid):
    lecture=0
    prog=""
    url='http://tv.voila.fr/index_chaine.html?c=%s'%(chanid)
    data=urllib2.urlopen(url)
    adatok=data.readlines()
    data.close()
    ii=0
    date1=dateok(1)
    date2=dateok(2)
    for i in range(len(adatok)):
          ligne=unicode(adatok[i],"cp1252")
    	  if (ligne.find(date1) > 0) :
             lecture=1   
          if (ligne.find(date2) > 0) :
             lecture=0
          if lecture==1 and ligne.find("drc")>0 :
             lignecop=ligne
             ligne=ligne.replace("<br>"," ")
             ligne=ligne.replace(" ","")
             ligne=ligne.replace("Showview : ","")
             ligne=ligne.replace("\\","")
             ligne=ligne.replace("*","")
	     if ligne.find("','")>0:
                x=ligne.find("','")
                if x>0 :
                    while ligne[x-1].isdigit()==1 :
                         ligne=ligne[:x-2]+ligne[x:]
                         x=ligne.find("','")
                    while ligne[x+3].isdigit()==1 :
                         ligne=ligne[:x+3]+ligne[x+4:]
                         x=ligne.find("','")
                ligne=ligne.replace("','","") 
                deb=ligne.find("('")+2
                fin=ligne.find("')\"")
                ii=ii+1
                prog=prog+"<br><b>"+(ligne[deb:fin])+"</b><br>"
                lignecop=ligne
                deb=ligne.find("href='javascript:of(")
                fin=ligne.find(")' onmouseover")
                if deb>0 : #ici on va rechercher les info du films....
                   nombre=ligne[deb+20:fin]
                   url="http://tv.voila.fr/fiche.html?id=%s"%(nombre)		   
                   dataf=urllib2.urlopen(url)
                   adatokf=dataf.readlines()
                   dataf.close()
                   for i in range(len(adatokf)):
                       ligne=unicode(adatokf[i],"cp1252")
                       if ligne.find("RESUME")>0 :
                          ligne=ligne.strip()
                          #avis,histoire,resumer
                          prog=prog+"<br>"+ligne+"<br>"
    return prog

class Fenetre :
     def __init__(self,Sys):
          self.App=Qt.QApplication(Sys.argv) # app
          self.Win=windows.Fenetre()                     # win = la fenetre

         
     def Signal(self):     
           self.App.connect(self.App, Qt.SIGNAL("lastWindowClosed()"), self.App, Qt.SLOT("quit()"))
           self.Win.connect(self.Win.listBox,Qt.SIGNAL("selected(int)"),self.Selected)
          
  
     def Main(self,Sys,chaine):
           self.Win.show()
           self.Win.text.setText(openChan(chaine["CLUBRTL"]))
           self.App.exec_loop()
           
     
     def List(self,chaine):
           for i in chaine :
                self.Win.listBox.insertItem(Qt.QPixmap("channels/%s.gif"%(i.lower())),i)

  
     def Selected(self, index):
           key=self.Win.listBox.currentText()   
           self.Win.text.setText(openChan(chaine["%s"%(key)]))
        
    
      
    

#-------------------------Main -----------------------------------
chaine=dict([('TF1',1),('FRANCE2',2),("FRANCE3",3),("AB3",132),("AB4",142),("ARTE",5),("RTBF",35),("RTBF2",104),("RTLTVI",54),("CLUBRTL",89),("PLUGTV",152),("M6",6),("MTV",31),("MCM",30),("TV5",10)])
image=open("channels/mcm.gif","r")
images=image.read()
image.close()
projet=Fenetre(Sys)
projet.List(chaine)
projet.Signal()
projet.Main(Sys,chaine)

Conclusion :


Voila une version graphique QT3, avec tt les sources....
pour les windosiens intaller le module PYQT

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.