Example #1
0
 def rechercherPLprocheDate(self, pdate):
     '''
     p1 date recherche de la PL selon cette date
     recherche toutes les playlist du meme jour que la date parametre
     si recherche > 1 playlist, on choisit celle qui est le plus proche de l'heure
     retourne le nom du fichier de la playlist'''
     jjmmaaaaParam = pdate.strftime('%d%m%Y')  #ex 21032017
     heureParam = pdate.strftime('%Hh%M')  #ex 15h00
     PLcriteresOK = [
     ]  #tableau des playlists qui ont le jour ok par rapport au parametre
     #on stocke l'heure du fichier
     ficPL = Util.listerRepertoire(
         Util.configValue('commun', 'repertoirePL'), False)
     for fichier in ficPL:
         retour = re.match(
             r"PL__([\d]{4})-([\d]{2})-([\d]{2})__([\d]{2})h00.obj",
             fichier)
         if retour:
             jjmmaaaaFichier = retour.group(3) + retour.group(
                 2) + retour.group(1)  #ex 21032017
             heureFichier = retour.group(4) + 'h00'  #ex 15h00
             if jjmmaaaaFichier == jjmmaaaaParam:
                 PLcriteresOK.append(retour.group() + ':' + heureFichier)
     if len(PLcriteresOK) == 0:
         raise CineException('PLRechercheKO')
     if len(PLcriteresOK) == 1:
         #une seule PL matche donc on la retourne
         return PLcriteresOK[0].split(':')[0]
     #il faut faire une recherche en prenant l'heure la plus proche'
     heurePlusProche = None  # heure fictive pour initialiser recherche
     for plTrouvee in PLcriteresOK:
         heurePL = plTrouvee.split(':')[1]
         if Util.heureCompare(heureParam, heurePL, heurePlusProche) < 0:
             plPlusProcheHeureParam = plTrouvee.split(':')[0]
             heurePlusProche = heurePL
     return plPlusProcheHeureParam
Example #2
0
    def rechercherInfosWebVideo(self, jourDiffusion):
        '''recherche des infos sur le site web du cinema lebeaulieu.
        jourDiffusion='1402201720
        retourne une oeuvre cinema en tant qu'objet
        '''
        dateFormatUrl = jourDiffusion[:2] + '%2F' + jourDiffusion[
            2:4] + '%2F' + jourDiffusion[4:8]
        heureDiffusion = jourDiffusion[8:10] + ':00'
        url = 'http://www.cinemalebeaulieu.com/programme.php?searchMode=date&RechercherDate=' + dateFormatUrl
        '''bug https avril 2019'''
        request = urllib.request.Request(url)
        try:
            response = urllib.request.urlopen(request)
        except HTTPError:
            raise CineWarning("AccesSiteBeaulieuKO")

        html = response.read().decode('utf-8')
        #parsing du code html pour retrouver les infos de l'oeuvre projete à une heure precise
        soup = BeautifulSoup(html, 'html.parser')
        articles = soup.find_all(
            class_="article"
        )  #un article correspond à une balise div d'une projection
        articlePlusProcheHeureParam = None
        heurePlusProche = '00:00'  # heure fictive pour initialiser recherche
        for filmProjete in articles:
            seance = filmProjete.find(class_="seance")
            if seance:
                heureSeance = seance.find(
                    class_="showtime").find_next("span").getText()  #Ex: 18h00
                # peut avoir 18h00 VO donc supprimer le VO
                heureSeanceFormattee = re.match(r"([\d]{2}):([\d]{2}).*",
                                                heureSeance)

                #comparaison de l'heure selectionnée dans ihm et heure affichee dans le site web
                if heureSeanceFormattee:
                    heureSeanceFormatteeParsee = heureSeanceFormattee.group(
                        1) + ':' + heureSeanceFormattee.group(2)
                    if Util.heureCompare(heureDiffusion,
                                         heureSeanceFormatteeParsee,
                                         heurePlusProche) < 0:
                        articlePlusProcheHeureParam = filmProjete
                        heurePlusProche = heureSeanceFormatteeParsee

        if articlePlusProcheHeureParam == None:
            '''probleme aucun film trouve sur le site'''
            raise CineWarning("parsingHtmlKO")
        #on prend les infos sur le site
        #parsing des balises images de la page html
        image = articlePlusProcheHeureParam.find("img")
        urlImage = image['src']
        '''bug librairie URL depuis avril 2019, impossible de requeter en https : solution utiliser http'''
        urlImage = urlImage.replace('https', 'http')
        urlImagePetite = urlImage.replace('ratio=0.5', 'ratio=0.2')
        #on calcule 2 images de taille differente
        titre = articlePlusProcheHeureParam.find(class_="titre").getText()
        infos = articlePlusProcheHeureParam.find(class_="infos").getText()
        synopsis = articlePlusProcheHeureParam.find(
            class_="synopsis").getText()

        #on construit objet a partir des donnes du site web
        oeuvre = Oeuvre(titre, infos, synopsis)
        #recuperation des images pour requete http
        repAffiche = Util.configValue('commun', 'repertoireAffiche')

        nomFichier1Affiche = repAffiche + urllib.parse.quote(
            titre, safe='') + '-G.jpg'
        oeuvre.setAfficheImage(2, nomFichier1Affiche)

        #on teste si le fichier jpeg a deja ete telecharge
        if not os.path.isfile(nomFichier1Affiche
                              ):  #le fichier image a t-il deja ete telecharge?
            urlretrieve(
                urlImage, nomFichier1Affiche
            )  #creer un fichier jpg dans le repertoire en telechargent par http

        nomFichier2Affiche = repAffiche + urllib.parse.quote(
            titre, safe='') + '-P.jpg'
        oeuvre.setAfficheImage(1, nomFichier2Affiche)
        if not os.path.isfile(nomFichier2Affiche):
            urlretrieve(urlImagePetite, nomFichier2Affiche)

        return oeuvre