Skip to content
Snippets Groups Projects
Verified Commit 7c9f5e88 authored by Frank Sauerburger's avatar Frank Sauerburger
Browse files

Add title-by-id lookup endpoint

parent a77db239
No related branches found
No related tags found
No related merge requests found
Pipeline #9639 failed
TAG=0.3.0
TAG=0.4.0
build:
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build -t gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:$(TAG) .
......
......@@ -4,7 +4,7 @@
"""Movie title suggestion api"""
import json
from flask import Flask, request
from flask import Flask, request, abort
import qgram
app = Flask(__name__)
......@@ -13,9 +13,12 @@ with open("examples/titles.json", encoding="utf-8") as fileobj:
titles = json.load(fileobj)
movie_ids = {}
movie_titles = {}
index = qgram.QGramIndex()
for tid, (title, _) in titles.items():
movie_ids[title] = int(tid)
for tid, (title, year) in titles.items():
tid = int(tid)
movie_titles[tid] = (title, year)
movie_ids[title] = tid
index.add_term(title)
......@@ -46,6 +49,20 @@ def suggest():
"suggestions": results
}
@app.route("/titles/<int:mid>")
def byid(mid):
"""Show healthz status"""
if mid not in movie_titles:
abort(404)
title, year = movie_titles[mid]
return {
"id": mid,
"title": title,
"year": year
}
@app.route("/titles/healthz")
def healthz():
"""Show healthz status"""
......
......@@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: titles
image: gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:0.3.0
image: gitlab.sauerburger.com:5049/frank/wakefield-movie-recommender:0.4.0
livenessProbe:
httpGet:
path: /titles/healthz
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment