Fixing some errorhandling bugs
authorFlorian Schweikert <kelvan@logic.at>
Wed, 19 Oct 2011 21:36:47 +0000 (23:36 +0200)
committerFlorian Schweikert <kelvan@logic.at>
Wed, 19 Oct 2011 21:36:47 +0000 (23:36 +0200)
Added automatic retry if incorrect site is received

gotovienna-qml
gotovienna/realtime.py

index 75e3803..cf551de 100755 (executable)
@@ -7,6 +7,10 @@ __version__ = '1.0'
 __website__ = 'https://github.com/kelvan/gotoVienna/'
 __license__ = 'GNU General Public License v3 or later'
 
 __website__ = 'https://github.com/kelvan/gotoVienna/'
 __license__ = 'GNU General Public License v3 or later'
 
+from datetime import datetime
+
+t = datetime.now()
+
 from PySide.QtCore import QAbstractListModel, QModelIndex, QObject, Slot, Signal
 from PySide.QtGui import QApplication
 from PySide.QtDeclarative import QDeclarativeView
 from PySide.QtCore import QAbstractListModel, QModelIndex, QObject, Slot, Signal
 from PySide.QtGui import QApplication
 from PySide.QtDeclarative import QDeclarativeView
@@ -153,6 +157,8 @@ if __name__ == '__main__':
         # Assume test from source directory, use relative path
         view.setSource(os.path.join(os.path.dirname(__file__), 'qml/main.qml'))
 
         # Assume test from source directory, use relative path
         view.setSource(os.path.join(os.path.dirname(__file__), 'qml/main.qml'))
 
+    print datetime.now() - t
+
     view.showFullScreen()
 
     sys.exit(app.exec_())
     view.showFullScreen()
 
     sys.exit(app.exec_())
index 0990fc1..6817b82 100644 (file)
@@ -110,15 +110,30 @@ class ITipParser:
             return []
 
         # open url for 90 min timeslot / get departure for next 90 min
             return []
 
         # open url for 90 min timeslot / get departure for next 90 min
-        bs = BeautifulSoup(urlopen(url + "&departureSizeTimeSlot=90"))
-        print url
-        lines = bs.findAll('table')[-2].findAll('tr')
-        if len(lines) == 1:
-            station = lines[0].span.text.replace('&nbsp;', '')
-            line = lines[0].findAll('span')[-1].text.replace('&nbsp;', '')
+        retry = 0
+        tries = 2
+        while retry < tries:
+            bs = BeautifulSoup(urlopen(url + "&departureSizeTimeSlot=90"))
+            try:
+                lines = bs.find('form', {'name': 'mainform'}).table.findAll('tr')[1]
+            except AttributeError:
+                print 'FetchError'
+                msg = bs.findAll('span', {'class': 'rot fett'})
+                if len(msg) > 0 and str(msg[0].text).find(u'technischen St') > 0:
+                    print 'Temporary problem'
+                    print '\n'.join(map(lambda x: x.text.replace('&nbsp;', ''), msg))
+                    # FIXME Change to error message after fixing qml gui
+                    return []
+                # FIXME more testing
+                retry += 1
+                if retry == tries:
+                    return []
+        if len(lines.findAll('td', {'class': 'info'})) > 0:
+            station = lines.span.text.replace('&nbsp;', '')
+            line = lines.findAll('span')[-1].text.replace('&nbsp;', '')
         else:
         else:
-            station = lines[1].td.span.text.replace('&nbsp;', '')
-            line = '??'
+            station = lines.td.span.text.replace('&nbsp;', '')
+            line = lines.find('td', {'align': 'right'}).span.text.replace('&nbsp;', '')
 
         result_lines = bs.findAll('table')[-1].findAll('tr')
 
 
         result_lines = bs.findAll('table')[-1].findAll('tr')