From 6a183e5b089605fc91e47757802de2b6ad1c107e Mon Sep 17 00:00:00 2001 From: Juke Date: Fri, 5 Feb 2010 20:03:01 +0100 Subject: [PATCH] VERSION 0.1.3 : Faire un objet ListeHoraire --- TODO | 7 +++++++ gtk_transilien.py | 57 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/TODO b/TODO index dde4fcb..63914b4 100644 --- a/TODO +++ b/TODO @@ -18,6 +18,7 @@ TODO : Remplacer liste des gares par un assesseur TODO : Remplacer get_liste_train par un assesseur TODO : Remplacer get_liste_horaire par un assesseur + TODO : Remplacer get_list_ligne_horaire par un assesseur TODO : Trier les gares par ordre alphabetique TODO : Intercepter les entrées vides TODO : ajouter les argument à l'url avec httplib @@ -27,9 +28,15 @@ TODO : corriger les noms des variables TODO : corriger la taille des lignes TODO : Fusionner liste horaire et liste train + TODO : etre ok sur pylint + TODO : faire des try sur les import + TODO : documenter les classes + DONE 0.1.1 : Modélisation Objet DONE 0.1.2 : Corriger l'indentation + DONE 0.1.3 : Faire un objet ListeHoraire + diff --git a/gtk_transilien.py b/gtk_transilien.py index 9286149..85d9406 100755 --- a/gtk_transilien.py +++ b/gtk_transilien.py @@ -14,6 +14,16 @@ app_name = 'NameOfYourApp' # the name of your app app_version = '1.0' # the version number of your app initial_mode = FremantleRotation.AUTOMATIC +class LigneHoraire(object): + def __init__(self, code_mission, heure_de_passage): + self.code_mission = code_mission + self.heure_de_passage = heure_de_passage + + def add_to_treestore(self, treestore): + print treestore + treestore.append(None, [self.code_mission, self.heure_de_passage]) + + class tableParser(HTMLParser.HTMLParser): def __init__(self): @@ -24,6 +34,7 @@ class tableParser(HTMLParser.HTMLParser): self.heure_de_passage = False self.liste_train = [] self.liste_horaire = [] + self.list_ligne_horaire = [] def handle_starttag(self, tag, attrs): if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')): @@ -52,6 +63,17 @@ class tableParser(HTMLParser.HTMLParser): def handle_endtag(self,tag): self.a_code_de_mission ^= (self.a_code_de_mission and tag == 'a') self.heure_de_passage ^= (self.heure_de_passage and tag == 'td') + + def get_list_ligne_horaire(self): + print 'get_list_ligne_horaire' + z = 0 + print self.liste_train + for i in self.liste_train: + self.list_ligne_horaire.append(LigneHoraire(code_mission=i, heure_de_passage=self.liste_horaire[z])) + z += 1 + return self.list_ligne_horaire + + class Trajet(object): def __init__(self, gare_source, gare_dest): @@ -60,13 +82,26 @@ class Trajet(object): self.parse() def get_liste_train(self): return self.p.liste_train - def get_liste_horaire(self): + def get_liste_horaire(self): return self.p.liste_horaire def parse(self): self.p = tableParser() - print "URL:" - print 'http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true' - self.p.feed(urllib2.urlopen('http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true').read()) + #print "URL:" + #print 'http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true' + rsrc = urllib2.urlopen('http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.gare_source.shortname+'&codeTr3aDest='+self.gare_dest.shortname+'&urlModule=/site/pid/184&gareAcc=true') + self.p.feed(rsrc.read()) + print "parsing ok" + + def refresh_treestore(self, treestore): + print 'refresh' + print treestore + + treestore.clear() + liste_ligne_horaire = self.p.get_list_ligne_horaire() + print liste_ligne_horaire + for i in liste_ligne_horaire: + print i + i.add_to_treestore(treestore) class ConfFile(object): def __init__(self, fichier): @@ -143,14 +178,12 @@ class TransilienUI: gtk.main_quit() def on_refreshButton_clicked(self, widget): - self.treestore.clear() - trajet = Trajet(LongNameGare(self.combo_source.get_current_text()).get_gare(ConfFile('example.cfg')), LongNameGare(self.combo_dest.get_current_text()).get_gare(ConfFile('example.cfg'))) - z=0 - for i in trajet.get_liste_train(): - liste_horaire = trajet.get_liste_horaire() - self.treestore.append(None, [i, liste_horaire[z]]) - z += 1 - + gare_source = LongNameGare(self.combo_source.get_current_text()).get_gare(ConfFile('example.cfg')) + gare_dest = LongNameGare(self.combo_dest.get_current_text()).get_gare(ConfFile('example.cfg')) + trajet = Trajet(gare_source , gare_dest) + print trajet + print self.treestore + trajet.refresh_treestore(self.treestore) if __name__ == "__main__": -- 1.7.9.5