Skip to content

Commit

Permalink
Merge pull request #4 from artemy/feature/3-places-with-spaces
Browse files Browse the repository at this point in the history
#3: Proper support for multi-word stations
  • Loading branch information
artemy authored Dec 28, 2022
2 parents 69b5e79 + 82e099a commit 32c8621
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Alfred workflow for getting NS Train schedule.

## Getting started

⚠️ This workflow requires [Alfred 5](https://www.alfredapp.com/alfred-5-whats-new/).
⚠️ This workflow requires [Alfred 5](https://www.alfredapp.com/alfred-5-whats-new/).
Alfred 4 users can use [version 2.0](https://github.com/artemy/alfred-ns-schedule/releases/tag/v2.0) of the workflow.

### Prerequisites
Expand All @@ -33,6 +33,8 @@ 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
2 changes: 1 addition & 1 deletion alfred/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Be sure to [get an API Key](https://apiportal.ns.nl/) and set it in the user con
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>3.0</string>
<string>3.1</string>
<key>webaddress</key>
<string>https://github.com/artemy/alfred-ns-schedule</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion ns_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def extract_arguments():
try:
args = sys.argv[1].split(' ')
if len(args) == 2:
return args
return [x.replace('_', ' ') for x in args]
raise IndexError
except IndexError:
raise NoArgsError
Expand Down
7 changes: 6 additions & 1 deletion ns_schedule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import urllib.request
from unittest import mock

from ns_schedule import create_json, create_headers, retrieve_schedule
from ns_schedule import create_json, create_headers, retrieve_schedule, extract_arguments


class Unittests(unittest.TestCase):
Expand Down Expand Up @@ -103,6 +103,11 @@ def test_bad_request(self, urlopen_mock):
expected = [{"title": "Error contacting server"}]
self.assertEqual(expected, retrieve_schedule())

@mock.patch("sys.argv", ["main", "Den_Haag_Centraal Amsterdam_Centraal"])
def test_argument_parsing(self):
expected = ["Den Haag Centraal", "Amsterdam Centraal"]
self.assertEqual(extract_arguments(), expected)


if __name__ == '__main__': # pragma: nocover
unittest.main()

0 comments on commit 32c8621

Please sign in to comment.