hubot-nextbus 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/nodejs.yml +26 -0
- package/README.md +21 -15
- package/package.json +17 -13
- package/src/nextbus.coffee +34 -19
- package/test/fixtures/agencies.json +20 -0
- package/test/fixtures/stops-CHA7AWN-trips.json +269707 -0
- package/test/fixtures/stops-near-gps.json +97 -0
- package/test/nextbus_test.coffee +23 -19
- package/.travis.yml +0 -11
- package/test/fixtures/findstop.json +0 -1
- package/test/fixtures/stop.json +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Node CI
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
node-version: [12.x, 14.x, 16.x]
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v1
|
|
16
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
17
|
+
uses: actions/setup-node@v1
|
|
18
|
+
with:
|
|
19
|
+
node-version: ${{ matrix.node-version }}
|
|
20
|
+
- name: npm install, build, and test
|
|
21
|
+
run: |
|
|
22
|
+
npm install
|
|
23
|
+
npm run build --if-present
|
|
24
|
+
npm test
|
|
25
|
+
env:
|
|
26
|
+
CI: true
|
package/README.md
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
# Hubot Nextbus (Nashville)
|
|
2
2
|
|
|
3
|
-
[](http://badge.fury.io/js/hubot-nextbus) [](http://badge.fury.io/js/hubot-nextbus) [](https://github.com/transitnownash/hubot-nextbus/actions/workflows/nodejs.yml)
|
|
4
4
|
|
|
5
|
-
This Hubot package
|
|
6
|
-
|
|
7
|
-
## Getting Started
|
|
8
|
-
|
|
9
|
-
The first step is to get an API key for this service. As it is currently in a private beta, you'll have to [ask the creator nicely](https://nextbus.jt2k.com/about). He's a swell guy.
|
|
5
|
+
This Hubot package works with . You provide an API key and a latitude and longitude for it to obtain the next expect bus to a particular set of nearby stops.
|
|
10
6
|
|
|
11
7
|
## Installation
|
|
12
8
|
|
|
@@ -24,8 +20,8 @@ Then add **hubot-nextbus** to your `external-scripts.json`:
|
|
|
24
20
|
|
|
25
21
|
| Environment Variable | Optional | Description |
|
|
26
22
|
| ----------------------- | :------: | ----------------------------------------|
|
|
27
|
-
|
|
28
|
-
| `
|
|
23
|
+
| `HUBOT_NEXTBUS_LAT_LON` | No | Default location for `hubot nextbus`, separated by a comma. (e.g. `36.1629191,-86.7813481`)|
|
|
24
|
+
| `HUBOT_NEXTBUS_BASE_URL`| Yes | URL of a `gtfs-rails-api` instance |
|
|
29
25
|
|
|
30
26
|
## Usage
|
|
31
27
|
|
|
@@ -35,7 +31,12 @@ Returns the next bus for the nearest stop.
|
|
|
35
31
|
|
|
36
32
|
```
|
|
37
33
|
user> hubot nextbus
|
|
38
|
-
hubot>
|
|
34
|
+
hubot> Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
|
|
35
|
+
7:01:09 #50 - CHARLOTTE WALMART in a minute
|
|
36
|
+
7:15:49 #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes
|
|
37
|
+
7:16:09 #50 - CHARLOTTE WALMART in 16 minutes
|
|
38
|
+
7:31:09 #50 - CHARLOTTE WALMART in 31 minutes
|
|
39
|
+
7:35:49 #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
### `hubot nextbus stops`
|
|
@@ -45,11 +46,11 @@ Get the list of stops nearby your configured latitude and longitude.
|
|
|
45
46
|
```
|
|
46
47
|
user> hubot nextbus stops
|
|
47
48
|
hubot> List of nearby stops:
|
|
48
|
-
hubot> -
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
hubot> - [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
|
|
50
|
+
- [CHA7AEN] CHARLOTTE AVE & 7TH AVE N EB
|
|
51
|
+
- [6AVDEASN] 6TH AVE & DEADERICK ST SB
|
|
52
|
+
- [6AVDEANN] 6TH AVE N & DEADERICK ST NB
|
|
53
|
+
- [UNI7AWN] UNION ST & 7TH AVE N WB
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
### `hubot nextbus stop <stop id>`
|
|
@@ -58,5 +59,10 @@ Returns the next bus for a given stop ID.
|
|
|
58
59
|
|
|
59
60
|
```
|
|
60
61
|
user> hubot nextbus stop 5AVCHUNM
|
|
61
|
-
hubot>
|
|
62
|
+
hubot> Upcoming Trips for [CHA7AWN] CHARLOTTE AVE & 7TH AVE N WB
|
|
63
|
+
7:01:09 #50 - CHARLOTTE WALMART in a minute
|
|
64
|
+
7:15:49 #17 - GREEN HILLS VIA 12TH AVE S in 16 minutes
|
|
65
|
+
7:16:09 #50 - CHARLOTTE WALMART in 16 minutes
|
|
66
|
+
7:31:09 #50 - CHARLOTTE WALMART in 31 minutes
|
|
67
|
+
7:35:49 #17 - GREEN HILLS VIA 12TH AVE S in 36 minutes
|
|
62
68
|
```
|
package/package.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hubot-nextbus",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "Shows when the next transit vehicle will arrive at a particular stop.",
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"author": "Stephen Yeargin <stephen@yearg.in>",
|
|
6
|
-
"homepage": "https://github.com/
|
|
6
|
+
"homepage": "https://github.com/transitnownash/hubot-nextbus",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"hubot",
|
|
10
10
|
"hubot-scripts",
|
|
11
11
|
"nextbus",
|
|
12
12
|
"bus",
|
|
13
|
-
"
|
|
13
|
+
"gtfs",
|
|
14
|
+
"gtfs-rails-api"
|
|
14
15
|
],
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
17
|
-
"url": "git://github.com/
|
|
18
|
+
"url": "git://github.com/transitnownash/hubot-nextbus.git"
|
|
18
19
|
},
|
|
19
20
|
"bugs": {
|
|
20
|
-
"url": "https://github.com/
|
|
21
|
+
"url": "https://github.com/transitnownash/hubot-nextbus/issues"
|
|
21
22
|
},
|
|
22
23
|
"peerDependencies": {
|
|
23
24
|
"hubot": "^3"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"chai": "^4.3.
|
|
27
|
+
"chai": "^4.3.6",
|
|
27
28
|
"coffee-script": "^1.12.7",
|
|
28
29
|
"hubot-test-helper": "^1.9.0",
|
|
29
|
-
"husky": "^
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"sinon": "^11.1.2",
|
|
30
|
+
"husky": "^8.0.1",
|
|
31
|
+
"mocha": "^10.0.0",
|
|
32
|
+
"nock": "^13.2.9",
|
|
33
|
+
"release-it": "^15.2.0",
|
|
34
|
+
"sinon": "^14.0.0",
|
|
35
35
|
"sinon-chai": "^3.7.0"
|
|
36
36
|
},
|
|
37
37
|
"main": "index.coffee",
|
|
@@ -39,5 +39,9 @@
|
|
|
39
39
|
"release": "release-it",
|
|
40
40
|
"test": "mocha --require coffee-script/register \"test/**/*.coffee\" --reporter spec",
|
|
41
41
|
"prepare": "husky install"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"ascii-table": "^0.0.9",
|
|
45
|
+
"moment-timezone": "^0.5.34"
|
|
42
46
|
}
|
|
43
47
|
}
|
package/src/nextbus.coffee
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Description:
|
|
2
|
-
# Get the next bus for a particular stop
|
|
2
|
+
# Get the next bus for a particular stop
|
|
3
3
|
#
|
|
4
4
|
# Configuration:
|
|
5
|
-
#
|
|
5
|
+
# HUBOT_NEXTBUS_BASE_URL - URL of a `gtfs-rails-api` instance
|
|
6
6
|
# HUBOT_NEXTBUS_LAT_LON - Default location for `hubot nextbus`
|
|
7
7
|
#
|
|
8
8
|
# Commands:
|
|
@@ -14,26 +14,28 @@
|
|
|
14
14
|
# Author:
|
|
15
15
|
# stephenyeargin
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
moment = require('moment-timezone')
|
|
18
|
+
AsciiTable = require('ascii-table')
|
|
19
|
+
baseURL = process.env.HUBOT_NEXTBUS_BASE_URL || 'https://gtfs.transitnownash.org'
|
|
18
20
|
latlon = process.env.HUBOT_NEXTBUS_LAT_LON
|
|
19
21
|
|
|
20
22
|
module.exports = (robot) ->
|
|
21
|
-
|
|
22
23
|
# query the default location's closest bus stop
|
|
23
24
|
robot.respond /(?:bus|nextbus)(?: me)?$/i, (msg) ->
|
|
24
|
-
getAPIResponse "
|
|
25
|
-
if stops
|
|
26
|
-
queryStopById stops[0].
|
|
25
|
+
getAPIResponse "stops/near/#{latlon}/1000.json?per_page=5", msg, (stops) ->
|
|
26
|
+
if stops.total > 0
|
|
27
|
+
queryStopById stops.data[0].stop_gid, msg
|
|
27
28
|
else
|
|
28
29
|
msg.send "No stops found near #{latlon}"
|
|
29
30
|
|
|
30
31
|
# get a list of nearby stops
|
|
31
32
|
robot.respond /(?:bus|nextbus) stops$/i, (msg) ->
|
|
32
|
-
getAPIResponse "
|
|
33
|
+
getAPIResponse "stops/near/#{latlon}/1000.json?per_page=5", msg, (stops) ->
|
|
33
34
|
msg.send "List of nearby stops:"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
output = []
|
|
36
|
+
for stop in stops.data
|
|
37
|
+
output.push "- [#{stop.stop_gid}] #{stop.stop_name}"
|
|
38
|
+
msg.send output.join("\n")
|
|
37
39
|
|
|
38
40
|
# get a particular stop's next bus
|
|
39
41
|
robot.respond /(?:bus|nextbus) stop ([A-Z0-9_]+)$/i, (msg) ->
|
|
@@ -42,15 +44,28 @@ module.exports = (robot) ->
|
|
|
42
44
|
queryStopById stop_id, msg
|
|
43
45
|
|
|
44
46
|
queryStopById = (stop_id, msg) ->
|
|
45
|
-
getAPIResponse
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
getAPIResponse 'agencies.json', msg, (agencies) ->
|
|
48
|
+
# Override timezone for moment() calls
|
|
49
|
+
process.env.TZ = agencies.data[0].agency_timezone
|
|
50
|
+
robot.logger.debug process.env.TZ
|
|
51
|
+
|
|
52
|
+
getAPIResponse "stops/#{stop_id}/trips.json?per_page=2000", msg, (trips) ->
|
|
53
|
+
nextTrips = trips.data.filter((i) => moment(moment().toISOString().split('T')[0] + ' ' + i.stop_times[0].arrival_time.trim().padStart(8, '0')).isAfter(moment(), 'second'))
|
|
54
|
+
robot.logger.debug nextTrips
|
|
55
|
+
if nextTrips.length == 0
|
|
56
|
+
return msg.send "The last bus has already run for today."
|
|
57
|
+
|
|
58
|
+
table = new AsciiTable()
|
|
59
|
+
stop = nextTrips[0].stop_times[0].stop
|
|
60
|
+
msg.send "Upcoming Trips for [#{stop.stop_gid}] #{stop.stop_name}"
|
|
61
|
+
for trip in nextTrips.slice(0, 5)
|
|
62
|
+
time = moment(moment().toISOString().split('T')[0] + ' ' + trip.stop_times[0].arrival_time.trim().padStart(8, '0'));
|
|
63
|
+
table.addRow [trip.stop_times[0].arrival_time, "##{trip.route_gid} - #{trip.trip_headsign}", time.fromNow()]
|
|
64
|
+
table.removeBorder()
|
|
65
|
+
msg.send table.toString()
|
|
51
66
|
|
|
52
|
-
getAPIResponse = (
|
|
53
|
-
url = "
|
|
67
|
+
getAPIResponse = (path, msg, cb) ->
|
|
68
|
+
url = "#{baseURL}/#{path}"
|
|
54
69
|
robot.logger.debug url
|
|
55
70
|
robot.http(url)
|
|
56
71
|
.get() (err, res, body) ->
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"total": 1,
|
|
3
|
+
"page": 1,
|
|
4
|
+
"per_page": 100,
|
|
5
|
+
"data": [
|
|
6
|
+
{
|
|
7
|
+
"id": 1,
|
|
8
|
+
"agency_gid": "WeGo Public Transit",
|
|
9
|
+
"agency_name": "WeGo Public Transit",
|
|
10
|
+
"agency_url": "http://www.wegotransit.com",
|
|
11
|
+
"agency_timezone": "America/Chicago",
|
|
12
|
+
"agency_lang": "en",
|
|
13
|
+
"agency_phone": "615-862-8833",
|
|
14
|
+
"agency_fare_url": null,
|
|
15
|
+
"agency_email": null,
|
|
16
|
+
"created_at": "2022-08-02T21:14:03.545-05:00",
|
|
17
|
+
"updated_at": "2022-08-02T21:14:03.545-05:00"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|