Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Filename : tvragetest.py
- Author : G.D. Walters
- Purpose : Cherche sur TVRage.com des informations sur des emissions TV
- """
- #=============================================================
- # IMPORTS
- #=============================================================
- from xml.etree import ElementTree as ET
- import urllib
- import sys
- #=============================================================
- # Classe principale
- #=============================================================
- class TvRage:
- def __init__(self):
- self.CleAPI = "Itnl8IyY1hsR9n0IP6zI"
- self.ChaineRechercheSerie = "http://services.tvrage.com/myfeeds/search.php?key="
- self.ChaineInformationEmission = "http://services.tvrage.com/myfeeds/showinfo.php?key="
- self.ChaineListeEpisodes = "http://services.tvrage.com/myfeeds/episode_list.php?key="
- self.ListeEmissions = []
- self.InfosEmissions = []
- self.ListeEpisodes = []
- self.ElementEpisode = []
- def TrouverIdParNom(self,nomEmission,debug = 0):
- chaine = self.ChaineRechercheSerie + self.CleAPI + "&show=" + nomEmission
- urllib.socket.setdefaulttimeout(8)
- usock = urllib.urlopen(chaine)
- resultat = ET.parse(usock).getroot()
- usock.close()
- compteurTrouves = 0
- self.listeEmissions = []
- for noeud in resultat.findall('show'):
- infosEmissions = []
- chaineGenre = None
- dict = {}
- for n in noeud:
- if n.tag == 'showid':
- showid = n.text
- dict['ID'] = showid
- elif n.tag == 'name':
- nomEmission = n.text
- dict['Nom'] = nomEmission
- elif n.tag == 'link':
- showlink = n.text
- dict['Lien'] = showlink
- elif n.tag == 'country':
- showcountry = n.text
- dict['Pays'] = showcountry
- elif n.tag == 'started':
- showstarted = n.text
- dict['Debut'] = showstarted
- elif n.tag == 'ended':
- showended = n.text
- dict['Fin'] = showended
- elif n.tag == 'seasons':
- showseasons = n.text
- dict['Saisons'] = showseasons
- elif n.tag == 'status':
- showstatus = n.text
- dict['Etat'] = showstatus
- elif n.tag == 'classification':
- showclassification = n.text
- dict['Classification'] = showclassification
- elif n.tag == 'genres':
- for sousElement in n:
- if sousElement.tag == 'genre':
- if sousElement.text != None:
- if chaineGenre == None:
- chaineGenre = sousElement.text
- else:
- chaineGenre += " | " + sousElement.text
- dict['Genres'] = chaineGenre
- compteurTrouves += 1
- self.listeEmissions.append(dict)
- return self.listeEmissions
- #========================================================
- def AfficheResultatsEmission(self, ListeEmissionsDict):
- tailleListe = len(ListeEmissionsDict)
- print "%d resultat(s)" % tailleListe
- print "------------------------"
- compteur = 1
- for c in ListeEmissionsDict:
- print "%d - %s - %s" % (compteur,c['Nom'],c['ID']) #,c['Fin'],c['Lien']
- compteur += 1
- sel = raw_input("Choisir un nombre ou 0 pour quitter -> ")
- return sel
- def main():
- tr = TvRage()
- #--------------------
- # Chercher une serie par son nom
- #--------------------
- nom = raw_input("Entrer le nom de la serie -> ")
- if nom != None:
- liste = tr.TrouverIdParNom(nom)
- choix = tr.AfficheResultatsEmission(liste)
- print "choix %d" % int(choix)
- if int(choix) == 0:
- sys.exit()
- else:
- option = int(choix)-1
- id = liste[option]['ID']
- print "Le ShowID choisi est %s" % id
- #===========================================================
- # Boucle principale
- #===========================================================
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement