Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit cdf0c8f

Browse files
Merge pull request #1473 from adamkaplan/master
Fix MTA API URL & exceptions while traversing the MTA response
2 parents e5b1f1b + 5212df7 commit cdf0c8f

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/scripts/mta.coffee

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = (robot) ->
2020
mtaMe msg
2121

2222
mtaMe = (msg) ->
23-
msg.http('http://mta.info/status/serviceStatus.txt')
23+
msg.http('http://web.mta.info/status/serviceStatus.txt')
2424
.get() (err, res, body) ->
2525
if err
2626
throw err
@@ -30,19 +30,21 @@ mtaMe = (msg) ->
3030
throw err
3131
re = new RegExp(msg.match[1], 'gi')
3232
if msg.match[1].length is 1 or msg.match[1].toUpperCase() is 'SIR'
33-
for k in res.service.subway.line
34-
str = k.name
35-
if str.match(re)
36-
switch k.status
37-
when "GOOD SERVICE"
38-
msg.send "the #{str} train is ok!"
39-
when "PLANNED WORK"
40-
msg.send "heads up, the #{str} train has planned work (updated #{k.Time})"
41-
when "SERVICE CHANGE"
42-
msg.send "the #{str} train has service changes (updated #{k.Time})"
43-
when "DELAYS"
44-
msg.send "the #{str} train is delayed (updated #{k.Time})"
45-
else
46-
msg.send "the #{str} train status is #{k.status}"
33+
for j in res.service.subway
34+
for k in j.line
35+
if k.name.length > 0
36+
str = k.name[0]
37+
if str.match(re)
38+
switch k.status
39+
when "GOOD SERVICE"
40+
msg.send "the #{str} train is ok!"
41+
when "PLANNED WORK"
42+
msg.send "heads up, the #{str} train has planned work (updated #{k.Time})"
43+
when "SERVICE CHANGE"
44+
msg.send "the #{str} train has service changes (updated #{k.Time})"
45+
when "DELAYS"
46+
msg.send "the #{str} train is delayed (updated #{k.Time})"
47+
else
48+
msg.send "the #{str} train status is #{k.status}"
4749
else
4850
msg.send "that's not a valid subway line!"

0 commit comments

Comments
 (0)