app_version = '1.0' # the version number of your app
initial_mode = FremantleRotation.AUTOMATIC
+
class tableParser(HTMLParser.HTMLParser):
- def __init__(self):
- HTMLParser.HTMLParser.__init__(self)
- self.table_horaires3 = False
- self.code_de_mission = False
- self.a_code_de_mission = False
- self.heure_de_passage = False
- self.liste_train = []
- self.liste_horaire = []
-
- def handle_starttag(self, tag, attrs):
- if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
- self.table_horaires3 = True
-
- elif self.table_horaires3 and tag == 'td':
- try:
- self.code_de_mission = (
- dict(attrs)['headers'] == 'Code_de_mission')
- self.heure_de_passage = (
- dict(attrs)['headers'] == 'Heure_de_passage')
- except KeyError:
- if dict(attrs).has_key('headers'):
- raise
- else:
- pass
- else:
- self.a_code_de_mission = (tag == 'a' and self.code_de_mission)
-
- def handle_data(self, data):
- if self.a_code_de_mission:
- self.liste_train.append(data.strip())
- if self.heure_de_passage:
- self.liste_horaire.append(data.strip())
-
- 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 __init__(self):
+ HTMLParser.HTMLParser.__init__(self)
+ self.table_horaires3 = False
+ self.code_de_mission = False
+ self.a_code_de_mission = False
+ self.heure_de_passage = False
+ self.liste_train = []
+ self.liste_horaire = []
+
+ def handle_starttag(self, tag, attrs):
+ if (tag == 'table' and (dict(attrs)['class'] == 'horaires3')):
+ self.table_horaires3 = True
+
+ elif self.table_horaires3 and tag == 'td':
+ try:
+ self.code_de_mission = (
+ dict(attrs)['headers'] == 'Code_de_mission')
+ self.heure_de_passage = (
+ dict(attrs)['headers'] == 'Heure_de_passage')
+ except KeyError:
+ if dict(attrs).has_key('headers'):
+ raise
+ else:
+ pass
+ else:
+ self.a_code_de_mission = (tag == 'a' and self.code_de_mission)
+
+ def handle_data(self, data):
+ if self.a_code_de_mission:
+ self.liste_train.append(data.strip())
+ if self.heure_de_passage:
+ self.liste_horaire.append(data.strip())
+
+ 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')
+
+class Trajet(object):
+ def __init__(self, gare_source, gare_dest):
+ self.gare_source = gare_source
+ self.gare_dest = gare_dest
+ self.parse()
+ def get_liste_train(self):
+ return self.p.liste_train
+ 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())
+
+class ConfFile(object):
+ def __init__(self, fichier):
+ self.c = ConfigParser.ConfigParser()
+ self.c.read(fichier)
+ def get_short_name(self, longname):
+ return self.c.get('ListeDesGares', longname)
+ def get_liste_des_gares(self):
+ return self.c.items('ListeDesGares')
+
+class LongNameGare(object):
+ def __init__(self, longname):
+ self.longname = longname
+ def get_gare(self, conffile):
+ short_name = conffile.get_short_name(self.longname)
+ return Gare(short_name)
+
+class Gare(object):
+ def __init__(self, shortname):
+ self.shortname = shortname
+
+
+
class TransilienUI:
- def __init__(self):
- mainWindow = hildon.Window()
- mainWindow.set_title("Horaires des Prochains Trains")
- mainWindow.connect("destroy", self.on_mainWindow_destroy)
+ def __init__(self):
+ mainWindow = hildon.Window()
+ mainWindow.set_title("Horaires des Prochains Trains")
+ mainWindow.connect("destroy", self.on_mainWindow_destroy)
- rotation_object = FremantleRotation(app_name, mainWindow, app_version, initial_mode)
- refreshButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
+ rotation_object = FremantleRotation(app_name, mainWindow, app_version, initial_mode)
+ refreshButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT,
hildon.BUTTON_ARRANGEMENT_HORIZONTAL, "Actualiser")
- refreshButton.connect("clicked", self.on_refreshButton_clicked)
-
- self.treestore = gtk.TreeStore(str, str)
- self.treeview = gtk.TreeView(self.treestore)
-
- self.tvcolumn_train = gtk.TreeViewColumn('Train', gtk.CellRendererText(), text=0)
- self.treeview.append_column(self.tvcolumn_train)
-
- self.tvcolumn_horaire = gtk.TreeViewColumn('Horaire', gtk.CellRendererText(), text=1)
- self.treeview.append_column(self.tvcolumn_horaire)
-
-
- picker_button_source = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
- picker_button_source.set_title("Gare de Depart")
- self.combo_source = hildon.TouchSelectorEntry(text=True)
- self.combo_dest = hildon.TouchSelectorEntry(text=True)
-
- self.c = ConfigParser.ConfigParser()
- self.c.read('example.cfg')
- for i in self.c.items('ListeDesGares'):
- self.combo_source.append_text(i[0])
- self.combo_dest.append_text(i[0])
- picker_button_source.set_selector(self.combo_source)
-
-
- picker_button_dest = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
- picker_button_dest.set_title("Gare d'arrivee")
- picker_button_dest.set_selector(self.combo_dest)
-
-
- vBox = gtk.VBox()
- hBox = gtk.HBox()
- vBox.pack_start(hBox)
- hBox.pack_start(picker_button_source)
- hBox.pack_start(picker_button_dest)
- vBox.pack_start(self.treeview)
- vBox.pack_start(refreshButton)
-
-
- mainWindow.add(vBox)
- mainWindow.show_all()
-
- def on_mainWindow_destroy(self, widget):
- gtk.main_quit()
-
- def on_refreshButton_clicked(self, widget):
- self.treestore.clear()
- p = tableParser()
- print self.c.get('ListeDesGares', self.combo_source.get_current_text())
- print self.c.get('ListeDesGares', self.combo_dest.get_current_text())
- p.feed(urllib2.urlopen('http://www.transilien.com/web/ITProchainsTrainsAvecDest.do?codeTr3aDepart='+self.c.get('ListeDesGares', self.combo_source.get_current_text())+'&codeTr3aDest='+self.c.get('ListeDesGares', self.combo_dest.get_current_text())+'&urlModule=/site/pid/184&gareAcc=true').read())
- z=0
- for i in p.liste_train:
- print p.liste_horaire[z]
- self.treestore.append(None, [i, p.liste_horaire[z]])
- z += 1
+ refreshButton.connect("clicked", self.on_refreshButton_clicked)
+
+ self.treestore = gtk.TreeStore(str, str)
+ self.treeview = gtk.TreeView(self.treestore)
+
+ self.tvcolumn_train = gtk.TreeViewColumn('Train', gtk.CellRendererText(), text=0)
+ self.treeview.append_column(self.tvcolumn_train)
+
+ self.tvcolumn_horaire = gtk.TreeViewColumn('Horaire', gtk.CellRendererText(), text=1)
+ self.treeview.append_column(self.tvcolumn_horaire)
+
+
+ picker_button_source = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ picker_button_source.set_title("Gare de Depart")
+ self.combo_source = hildon.TouchSelectorEntry(text=True)
+ self.combo_dest = hildon.TouchSelectorEntry(text=True)
+
+ for i in ConfFile('example.cfg').get_liste_des_gares():
+ self.combo_source.append_text(i[0])
+ self.combo_dest.append_text(i[0])
+ picker_button_source.set_selector(self.combo_source)
+
+
+ picker_button_dest = hildon.PickerButton(gtk.HILDON_SIZE_AUTO, hildon.BUTTON_ARRANGEMENT_VERTICAL)
+ picker_button_dest.set_title("Gare d'arrivee")
+ picker_button_dest.set_selector(self.combo_dest)
+
+ vBox = gtk.VBox()
+ hBox = gtk.HBox()
+ vBox.pack_start(hBox)
+ hBox.pack_start(picker_button_source)
+ hBox.pack_start(picker_button_dest)
+ vBox.pack_start(self.treeview)
+ vBox.pack_start(refreshButton)
+
+
+ mainWindow.add(vBox)
+ mainWindow.show_all()
+
+ def on_mainWindow_destroy(self, widget):
+ 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
+
+
if __name__ == "__main__":
- TransilienUI()
- gtk.main()
+ TransilienUI()
+ gtk.main()