-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from dbatten5/search-movies
Search movies
- Loading branch information
Showing
12 changed files
with
167 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
`phylm` also offers some tools and utilities related to movies. | ||
|
||
# Search movies | ||
|
||
For a given movie title query you can return a list of search results from `IMDb` | ||
through `get_suggestions`: | ||
|
||
```python | ||
>>> from phylm.tools import search_movies | ||
>>> search_movies("the matrix") | ||
[{ | ||
'title': 'The Matrix', | ||
'kind': 'movie', | ||
'year': 1999, | ||
'cover url': 'https://some-url.com', | ||
'imdb_id': '0133093', | ||
}, { | ||
'title': 'The Matrix Reloaded', | ||
'kind': 'movie', | ||
'year': 2003, | ||
'cover url': 'https://some-url.com', | ||
'imdb_id': '0234215', | ||
}, { | ||
... | ||
``` | ||
|
||
::: phylm.tools.search_movies | ||
rendering: | ||
show_signature_annotations: true | ||
heading_level: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "phylm" | ||
version = "4.0.2" | ||
version = "4.0.3" | ||
description = "Phylm" | ||
authors = ["Dom Batten <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Module to hold `phylm` tools.""" | ||
from typing import Dict | ||
from typing import List | ||
from typing import Union | ||
|
||
from imdb.Movie import Movie | ||
|
||
from phylm.sources.imdb import ia | ||
|
||
|
||
def search_movies(query: str) -> List[Dict[str, Union[str, int]]]: | ||
"""Return a list of search results for a query. | ||
Args: | ||
query: the search query | ||
Returns: | ||
a list of search results | ||
""" | ||
results: List[Movie] = ia.search_movie(query) | ||
|
||
return [{**r.data, "imdb_id": r.movieID} for r in results] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Tests for the `tools` module.""" | ||
from typing import List | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from imdb import IMDb | ||
from imdb.Movie import Movie | ||
|
||
from phylm.tools import search_movies | ||
|
||
ia = IMDb() | ||
|
||
|
||
TOOLS_MODULE_PATH = "phylm.tools" | ||
|
||
|
||
@pytest.fixture(scope="module", name="the_matrix") | ||
def the_matrix_fixture() -> List[Movie]: | ||
"""Return The Matrix IMDb Movie object.""" | ||
return list(ia.search_movie("The Matrix")) | ||
|
||
|
||
class TestSearchMovies: | ||
"""Tests for the `search_movies` function.""" | ||
|
||
@patch(f"{TOOLS_MODULE_PATH}.ia", autospec=True) | ||
def test_results(self, mock_ia: MagicMock, the_matrix: List[Movie]) -> None: | ||
""" | ||
Given a search query, | ||
When the `search_movies` function is invoked with the query, | ||
Then a list of search results is returned | ||
""" | ||
mock_ia.search_movie.return_value = the_matrix | ||
|
||
result: List[Movie] = search_movies("the matrix") | ||
|
||
assert len(result) | ||
assert result[0]["imdb_id"] == "0133093" | ||
assert result[0]["title"] == "The Matrix" | ||
assert result[0]["year"] == 1999 | ||
assert result[0]["cover url"] |