# coding: utf-8 def makefeedauvio(pid): """get an Atom feed from the pid of an auvio (pid is in the URL when you're on a show page)""" import requests as rq from bs4 import BeautifulSoup from feedgen.feed import FeedGenerator #generate Atom Feed fg = FeedGenerator() fg.id('http://www.rtbf.be/auvio/') fg.title(u'Auvio') fg.logo('http://www.static.rtbf.be/tv/media/images/ico/favicon-auvio-32x32.png') fg.subtitle(u"Flux Atom d'une émission d'Auvio.") feedlink = u'http://gauchiste.club/auvio/' + str(pid) fg.link(href=(feedlink), rel='self') fg.language(u'fr_BE') #obtain page html lien="https://www.rtbf.be/auvio/archives?pid="+str(pid)+"&contentType=complete" response = rq.get(lien) soup = BeautifulSoup(response.content, features="lxml") jolihtml=soup.prettify() listpage=jolihtml.split() #analyze the html from the page i=0 autravail=False listinfo=[] lepremier=True TitreIncomplet=True #Grosse boucle d'analyse du HTML et mise en place dans un fichier XML for elements in listpage: if "rtbf-media-li__header" in elements and autravail== False: #on va ici que si on commence une partie avec des infos interessantes, sinon la boucle va dans le else non noté et rajoute juste un à i autravail = True elif autravail == True and "/time" in elements : #normalement, on a la liste complète avec les infos qui nous conviennent ici. On arrive ici uniquement quand le elif en dessous a fini de tourner. autravail = False #fc = fg.add_entry() if lepremier==True: #We don't use the first list because the first list given by the methode give us something totally unrelated and useless in all cases lepremier=False else: #l'id et le lien monHref=listinfo[3] IdLien=monHref[6:-2] #le titre j=4 titre=u'' #4 car le titre est en position 4 dans la liste while TitreIncomplet==True: if '/a' in listinfo[j]: TitreIncomplet=False titre=titre + IdLien else: titre=titre+listinfo[j]+u' ' j+=1 #mettre les éléments dans feed fe = fg.add_entry() fe.id(IdLien) fe.title(titre) fe.link(href=IdLien) TitreIncomplet=True listinfo=[] elif autravail== True: #au travail, on rajoute dans une liste les éléments qui nous interessent. toadd=listpage[int(i)] listinfo.append(toadd) i+=1 #exporter le feed #atomfeed = fg.atom_str(pretty=True) fg.atom_file(u''+str(pid)+u'.xml') #return atomfeed def makefeedVRTNU()