Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoulder4 authored Aug 19, 2023
1 parent ba5ebfd commit 5b022e6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ example response:
```

# Tracking a train
`trackTrain(serviceID, date?, timeTillRefresh?)`

Emit live updates on a train until it's journey is complete. You first need the `serviceID`. Retrieved by `findTrains(stationNameOrCode)` as shown above.
```js
trackTrain(serviceID, date?, timeTillRefresh?) //-> Promise<typeof EventEmitter>
```
_**🌻 Note**: Date must be in the form YYYY-MM-DD, defaults to today_


E.g. ServiceID `P70052` departing on 18/08/2023:

Expand All @@ -71,7 +70,7 @@ trackTrain("P70052", "2023-08-18").then((emitter) => {
});
});
```
_🌻 Note you must enter an event name of "journey" for journey updates, and "information" for information (error, cancellation etc.) updates._
_**🌻 Note**: Date must be in the form YYYY-MM-DD, defaults to today. You must enter an event name of "journey" for journey updates, and "information" for information (error, cancellation etc.) updates._

Example journey update:
```js
Expand Down Expand Up @@ -164,8 +163,8 @@ Track the next service from London to Manchester, today:
```js
import { trackTrain, findTrains } from "trainspy";

const services = await findTrains("EUS");
const serviceID = service.departures.find(departure => departure.destination == "Manchester Piccadilly")
const response = await findTrains("EUS");
const serviceID = response.departures.find(departure => departure.destination == "Manchester Piccadilly")
trackTrain(serviceID).then((emitter) => {
emitter.on("journey", (update) => {
//do stuff!
Expand All @@ -185,7 +184,7 @@ class trainInformationComponent extends Component {
};

trackTrain("P56592").then(emitter=>{
emitter.on("journey",(journeyUpdate)=>{
emitter.on("journey",(update)=>{
handleInfoChange(update);
})
});
Expand All @@ -210,5 +209,5 @@ class trainInformationComponent extends Component {
}
};
```
A project by Tye.
Special thanks to @ellcom for their list of longitude & latitude for each station, and to RealTimeTrains for providing the primitives for this project.

0 comments on commit 5b022e6

Please sign in to comment.