During local hack day this December, I developed an Alexa skill for students to check bus times through campus transportation. It was a solo project I set out to complete in 10 hours, and as of January of 2019, over 30 students are still actively invoking the skill every week.

Development

The process of building Alexa skills has changed a lot over time, but when this skill was created, the “Skill Builder” was still in beta. So instead, I just used an AWS Lambda function to control requests to our transportations API.

I never earned an API key, but luckily, using “XXXX” (the key that was used in the demonstration documentation page), allowed for unlimited requests :). In writing this post, I found their developer facebook page and API documentation, and they’ve acknowledged the public key and now encourage developers to use it.

Interacting with the API ● GitHubAlexa Skill

Below is the script I used to interact with the Bongo API. As of January 2019, it still works, so feel free to use it in your own projects. The lambda function version I used for the Alexa Skill is also available as a separate script on the GitHub repo. It’s a great beginners project because it could easily be turned into a full wrapper, and the skill has many more potential improvements, so feel free to make pull requests!

stopInfoDemo.py - GitHub
  • python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json, urllib.request
import string

def routeListing():
with urllib.request.urlopen("http://api.ebongo.org/routelist?format=json&api_key=XXXX") as url:
mainDict = json.loads(url.read().decode())

mainList = mainDict['routes']

for routeDict in mainList:
routeInfoDict = routeDict["route"]
print("ID: ",routeInfoDict["id"])

def predictions(stop = 1015):
stopID = stop
print("Searching for " + str(stopID))
requestString = "http://api.ebongo.org/prediction?stopid=" + str(stopID) + "&api_key=XXXX"
with urllib.request.urlopen(requestString) as url:
mainDict = json.loads(url.read().decode())

predictionsList = mainDict["predictions"]
#print(predictionsList)

if predictionsList == []:
print("No predictions for stop " + str(stopID) +"."
+" Busses must not be running right now.")

else:
less30 = True
#i representing the amount of busses within 30 mintues
i = 0

while less30:
if predictionsList[i]["minutes"] > 30:
less30 = False
else:
print("Theres a",predictionsList[i]['title'],"in",predictionsList[i]['minutes'],"coming to stop ",stopID)
i = i + 1

def main():
stop = int(input("Please Enter Stop ID: ")) #1015 is currier bus stop near burge
predictions(stop)

if **name** == "**main**":
main()