- 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(' ', '')
- line = lines[0].findAll('span')[-1].text.replace(' ', '')
+ 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(' ', ''), 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(' ', '')
+ line = lines.findAll('span')[-1].text.replace(' ', '')