API
Run the server
The package also provides API functionality to interact with the recommendation model. To run the server, you need to run the run.py file:
python run.py
kitab.api.app
This module contains the API for the book recommendation system.
add_book(book)
Add a book to the database.
Parameters: book (dict): The book information.
Source code in kitab\api\app.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
add_log(description, recommendation_isbn, successful)
Add a log of a recommendation.
Parameters: description (str): The description of the book. recommendation_isbn (str): The ISBN of the recommended book. successful (bool): Whether the recommendation was successful.
Source code in kitab\api\app.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
get_book_isbn(isbn)
Get the book by ISBN.
Parameters: ISBN (str): The ISBN of the book.
Returns: dict: The book information.
Source code in kitab\api\app.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
get_book_title(title)
Get the book by title.
Parameters: title (str): The title of the book.
Returns: dict: The book information.
Source code in kitab\api\app.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_logs(recommendation_isbn)
Return the history of recommendations for the book with the given ISBN.
Parameters: recommendation_isbn (str): The ISBN of the book.
Returns: dict: The history of recommendations.
Source code in kitab\api\app.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
get_recommendations(description, n, get_available=True)
Return n book recommendations based on the description.
Parameters: description (str): The description of the book. n (int): The number of recommendations to return. get_available (bool, optional): Whether to only recommend available books. Defaults to True.
Returns: dict: The recommendations.
Source code in kitab\api\app.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
get_recommendations_by_isbn(isbn, n, get_available=True)
Return n book recommendations based on recommendation of the book with the given ISBN.
Parameters: ISBN (str): The ISBN of the book. n (int): The number of recommendations to return. get_available (bool, optional): Whether to only recommend available books. Defaults to True.
Returns: dict: The recommendations.
Source code in kitab\api\app.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
get_recommendations_by_title(title, n, get_available=True)
Return n book recommendations based on recommendation of the book with the given title.
Parameters: title (str): The title of the book. n (int): The number of recommendations to return. get_available (bool, optional): Whether to only recommend available books. Defaults to True.
Returns: dict: The recommendations.
Source code in kitab\api\app.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
run_api(port=5552)
Run the API server.
Examples:
>>> from kitab.utils import run_api
>>> run_api(port=5552)
Parameters: port (int): The port number on which the API server will run.
Returns: None
Source code in kitab\api\app.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
update_book(isbn, new_book)
Update a book in the database.
Parameters: ISBNs (str): The ISBN of the book. new_book (dict): The new book information.
Source code in kitab\api\app.py
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 151 | |