Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from JamesIves/local-timestring
Browse files Browse the repository at this point in the history
Adds local timezone for EST
  • Loading branch information
JamesIves authored Dec 5, 2018
2 parents 18e9ae7 + b5c5df3 commit 2194962
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Binary file modified DC-Metro.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dc-metro-google-assistant-action",
"description": "DC Metro Google Assistant action that will show you the latest train and bus arrival information for your commute.",
"version": "1.0.2",
"version": "1.0.3",
"author": "James Ives",
"license": "MIT",
"scripts": {
Expand Down
36 changes: 25 additions & 11 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ app.intent(
) => {
const transportParam = transport.toLowerCase();

if (transportParam === 'train' || transportParam === 'rail') {
if (
transportParam === 'train' ||
transportParam === 'rail' ||
transportParam === 'metro'
) {
const timetable: any = await fetchTrainTimetable(station);

if (!timetable) {
conv.close(
'I was not able to find a station by that name. Please double check the name you provided and try again.'
conv.ask(
`I couldn't find a station by that name. Please could you repeat that request for me?`
);
} else {
// Generates the neccersary table cells for display devices.
Expand Down Expand Up @@ -84,7 +88,9 @@ app.intent(
conv.ask(
new Table({
title: timetable.stationName,
subtitle: new Date().toLocaleString(),
subtitle: new Date().toLocaleString('en-US', {
timeZone: 'America/New_York',
}),
image: new Image({
url:
'https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/WMATA_Metro_Logo_small.svg/1024px-WMATA_Metro_Logo_small.svg.png',
Expand Down Expand Up @@ -197,7 +203,9 @@ app.intent(
conv.ask(
new Table({
title: timetable.StopName,
subtitle: new Date().toLocaleString(),
subtitle: new Date().toLocaleString('en-US', {
timeZone: 'America/New_York',
}),
image: new Image({
url:
'https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/WMATA_Metro_Logo_small.svg/1024px-WMATA_Metro_Logo_small.svg.png',
Expand Down Expand Up @@ -253,12 +261,14 @@ app.intent(
}
}
} else {
conv.close(
'I could not find a bus stop with that id. Please double checkthe number and try again, the stop id is located on the sign that the bus stops at.'
conv.ask(
'I could not find a bus stop with that id. The stop id is located on the sign that the bus stops at. Please could you repeat that request for me?'
);
}
} else {
conv.ask(`I wasn't able to understand your request, please try again.`);
conv.ask(
`I wasn't able to understand your request, please could you try that again?`
);
}
}
);
Expand All @@ -271,13 +281,17 @@ app.intent(
async (conv: any, {transport}: {transport: string}) => {
const transportParam = transport.toLowerCase();

if (transportParam === 'train' || transportParam === 'rail') {
if (
transportParam === 'train' ||
transportParam === 'rail' ||
transportParam === 'metro'
) {
conv.ask(
`To get the next train arrival at a Metro station you can say things such as 'Train timetable for Farragut North' or 'Rail timetable for Smithsonian'. What would you like me to do?`
`To get the next train arrival at a Metro station you can say things such as 'Train times for Farragut North' or 'Rail times for Smithsonian'. What would you like me to do?`
);
} else if (transportParam === 'bus') {
conv.ask(
`To find out when the next bus arrives you can say 'Bus timetable for 123', replacing the 123 with the stop id found on the Metro bus stop sign. What would you like me to do?`
`To find out when the next bus arrives you can say 'Bus times for 123', replacing the 123 with the stop id found on the Metro bus stop sign. What would you like me to do?`
);
} else {
conv.ask(
Expand Down
4 changes: 2 additions & 2 deletions functions/src/wmata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const fetchTrainTimetable = async (station: string): Promise<object> => {
const predictionObj = await predictionResponse.json();
const predictionData = await predictionObj.Trains.filter(
(item) =>
(item.Line !== 'None' || item.Line !== 'No') &&
item.Destination !== 'ssenger'
(item.Line !== 'None' && item.Line !== 'No') &&
(item.Destination !== 'ssenger' && item.Destination !== 'Train')
);

return {
Expand Down

0 comments on commit 2194962

Please sign in to comment.