tcl: add workarounds for bad/changed line references (#33810)

This commit is contained in:
Frédéric Péters 2019-08-18 10:59:35 +02:00
parent b47cc866c3
commit 361be2c492
1 changed files with 21 additions and 7 deletions

View File

@ -58,14 +58,25 @@ class Tcl(BaseResource):
response.raise_for_status()
passings_by_line = {}
metro_lines = {
'301': 'A',
'302': 'B',
'303': 'C',
'304': 'D',
'325': 'F1',
'326': 'F2',
}
for k, v in metro_lines.items(): # additional codes...
metro_lines[k+'A'] = v
for passing in response.json()['values']:
try:
line = Line.objects.filter(code_titan_short=passing['ligne'])[0]
except IndexError:
passing['line_info'] = {'ligne': passing['ligne']}
else:
passing['line_info'] = line.get_info_dict()
for line_code in (passing['ligne'], passing['ligne'][:-1], metro_lines.get(passing['ligne'])):
try:
line = Line.objects.filter(code_titan_short=line_code)[0]
except IndexError:
passing['line_info'] = {'ligne': passing['ligne']}
else:
passing['line_info'] = line.get_info_dict()
break
stop['passings'].append(passing)
# create dictionary key from both line number and direction
line_info_key = passing['line_info']['ligne'] + '-' + passing['direction']
@ -192,6 +203,9 @@ class Line(models.Model):
self.html_bg_color = '%02x%02x%02x' % tuple(int(x) for x in self.couleur.split())
self.html_fg_color = self.get_foreground_colour(self.html_bg_color)
self.code_titan_short = re.sub(r'[abr].*', '', self.code_titan)
if '-' in self.code_titan_short:
# new code format, apparently <code>-\d
self.code_titan_short = self.code_titan_short.split('-')[0]
# compute display parts
if self.transport_key == 'tcllignebus' and self.ligne.startswith('C'):