Reference
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
movie_guess
project code.
utils
Utility functions.
general
General utility functions.
check_env_vars
check_env_vars(env_vars=None)
Checks if the required environment variables are set.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env_vars
|
list[str] | None
|
List of environment variables to check. Defaults to None. |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If any of the environment variables are not set. |
Source code in api/utils/general.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
is_module_installed
is_module_installed(module_name, throw_error=False)
Check if the module is installed or not.
Examples:
>>> is_module_installed(module_name="yaml", throw_error=False)
True
>>> is_module_installed(module_name="numpy", throw_error=False)
False
>>> is_module_installed(module_name="numpy", throw_error=True)
Traceback (most recent call last):
ImportError: Module numpy is not installed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
Name of the module to be checked. |
required |
throw_error
|
bool
|
If True, raises ImportError if module is not installed. |
False
|
Returns:
Type | Description |
---|---|
bool
|
Returns True if module is installed, False otherwise. |
Raises:
Type | Description |
---|---|
ImportError
|
If throw_error is True and module is not installed. |
Source code in api/utils/general.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
movie
Utility functions for interacting with the TMDB API.
fuzzy_search_movies
fuzzy_search_movies(query, threshold=60, limit=5, include_backdrops=True)
Search movies with fuzzy matching.
Examples:
>>> results = fuzzy_search_movies("Matrix")
>>> isinstance(results, list)
True
>>> all(isinstance(movie, dict) for movie in results)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search term to look for. |
required |
threshold
|
int
|
Minimum similarity score (0-100) for fuzzy matching. |
60
|
limit
|
int
|
Maximum number of results to return. |
5
|
include_backdrops
|
bool
|
Whether to include backdrop images in results (default: True). |
True
|
Returns:
Type | Description |
---|---|
list[dict] | None
|
A list of movie dictionaries that match the search criteria, or None if no matches found. |
Source code in api/utils/movie.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
get_movie_backdrops
get_movie_backdrops(movie_id)
Get all available backdrops for a movie.
Examples:
>>> backdrops = get_movie_backdrops(550)
>>> isinstance(backdrops, list)
True
>>> all(isinstance(path, str) for path in backdrops)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
movie_id
|
int
|
The TMDB ID of the movie. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list of strings representing backdrop file paths. |
Source code in api/utils/movie.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
get_movie_posters
get_movie_posters(movie_id)
Get all available posters for a movie.
Examples:
>>> posters = get_movie_posters(550)
>>> isinstance(posters, list)
True
>>> all(isinstance(path, str) for path in posters)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
movie_id
|
int
|
The TMDB ID of the movie. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
A list of strings representing poster file paths. |
Source code in api/utils/movie.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
get_random_movie
get_random_movie(category='popular')
Get a random movie from specified TMDB category.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
category
|
str
|
The category to select from (default: "popular") Options: "popular", "top_rated", "now_playing", "upcoming" |
'popular'
|
Returns:
Type | Description |
---|---|
Movie
|
A Movie object representing a randomly selected movie from the specified category. |
Source code in api/utils/movie.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
get_random_movie_with_details
get_random_movie_with_details(min_backdrops=5, category='popular', depth=0, max_depth=5)
Get a random movie with at least specified number of backdrops.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_backdrops
|
int
|
Minimum number of backdrops required (default: 5) |
5
|
category
|
str
|
The category to select from (default: "popular") Options: "popular", "top_rated", "now_playing", "upcoming" |
'popular'
|
depth
|
int
|
Current recursion depth (default: 0) |
0
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing movie details including title, backdrops, etc. |
Source code in api/utils/movie.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|