Skip to content

Commit

Permalink
Merge pull request #8 from MartinKanters/feature/autocomplete-station…
Browse files Browse the repository at this point in the history
…-names

Autocomplete the names of the arrival and destination station.
  • Loading branch information
artemy authored Jul 6, 2024
2 parents 32c8621 + b0cbae2 commit 84cb3f5
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 27 deletions.
Binary file modified .readme/images/animation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Project requires Python 3.8+ to run, which is not included by default with macOS
this [guide](https://docs.python-guide.org/starting/install3/osx/).

⚠️ Make sure to get API key from https://apiportal.ns.nl/ and set it in a user configuration of the workflow.
Subscribe to the product [NS-App](https://apiportal.ns.nl/product#product=NsApp).

### Installing

Expand All @@ -27,14 +28,12 @@ Change the value of NS_APIKEY variable to the value you've received from NS at t

### How to Use

Open Alfred and type `ns` and names of two train stations you want to see schedule for. Workflow will display list of
Open Alfred and type `ns` and names of the origin station followed by the destination station you want to see schedule for. Workflow will display list of
upcoming trains for the route you have specified. Pressing `Enter` on a displayed item will open it on NS website, so
you can get more details.

![animation](.readme/images/animation.gif)

> ⚠️ For places with names consisting of multiple words, use `_` (underscore) instead of space inside the name, e.g. for trains between Den Haag Centraal and Amsterdam Bijlmer Arena type `den_haag_centraal amsterdam_bijlmer_arena`
## Running the tests

Make sure to first install test dependencies:
Expand Down
204 changes: 191 additions & 13 deletions alfred/info.plist

Large diffs are not rendered by default.

12 changes: 1 addition & 11 deletions ns_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,9 @@ def new_item_from_trip(trip):
'arg': trip['shareUrl']['uri']}


def extract_arguments():
try:
args = sys.argv[1].split(' ')
if len(args) == 2:
return [x.replace('_', ' ') for x in args]
raise IndexError
except IndexError:
raise NoArgsError


def retrieve_schedule():
try:
(origin, destination) = extract_arguments()
(origin, destination) = sys.argv[1], sys.argv[2]

response = call_api(origin, destination)
return [new_item_from_trip(trip) for trip in response['trips']]
Expand Down

0 comments on commit 84cb3f5

Please sign in to comment.