mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 13:23:06 +02:00
zabawy z cache
This commit is contained in:
parent
52e509404e
commit
f702d18251
31
Dockerfile
31
Dockerfile
@ -1,15 +1,26 @@
|
||||
FROM node:latest
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.10-slim
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app
|
||||
|
||||
# Install app dependencies
|
||||
# Install necessary OS packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# If you also need http-server globally
|
||||
RUN npm install -g http-server
|
||||
# Copy the Python script, requirements, and constants.ini file into the container at /app
|
||||
COPY connector/Include/frontend_AI_connector.py /app/
|
||||
COPY connector/Include/requirements.txt /app/
|
||||
COPY connector/Include/init_scripts/constants.ini /app/init_scripts/
|
||||
COPY connector/Include/init_scripts/movies.csv /app/init_scripts/
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
# Modify requirements.txt to use psycopg2-binary
|
||||
RUN sed -i 's/psycopg2==2.9.9/psycopg2-binary==2.9.9/' requirements.txt
|
||||
|
||||
EXPOSE 8080
|
||||
CMD ["http-server", "-p 8080"]
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Run frontend_AI_connector.py when the container launches
|
||||
CMD ["python", "./frontend_AI_connector.py"]
|
||||
@ -1,25 +0,0 @@
|
||||
# Use an official Python runtime as a parent image
|
||||
FROM python:3.10-slim
|
||||
|
||||
# Set the working directory to /app
|
||||
WORKDIR /app
|
||||
|
||||
# Install necessary OS packages
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the Python script, requirements, and constants.ini file into the container at /app
|
||||
COPY connector/Include/frontend_AI_connector.py /app/
|
||||
COPY connector/Include/requirements.txt /app/
|
||||
COPY connector/Include/init_scripts/constants.ini /app/init_scripts/
|
||||
|
||||
# Modify requirements.txt to use psycopg2-binary
|
||||
RUN sed -i 's/psycopg2==2.9.9/psycopg2-binary==2.9.9/' requirements.txt
|
||||
|
||||
# Install any needed packages specified in requirements.txt
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Run frontend_AI_connector.py when the container launches
|
||||
CMD ["python", "./frontend_AI_connector.py"]
|
||||
15
Dockerfile_frontend
Normal file
15
Dockerfile_frontend
Normal file
@ -0,0 +1,15 @@
|
||||
FROM node:latest
|
||||
|
||||
# Create app directory
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Install app dependencies
|
||||
|
||||
# If you also need http-server globally
|
||||
RUN npm install -g http-server
|
||||
|
||||
# Bundle app source
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8080
|
||||
CMD ["http-server", "-p 8080"]
|
||||
@ -1,11 +1,14 @@
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_caching import Cache
|
||||
import psycopg2
|
||||
import pandas
|
||||
import json
|
||||
from configparser import ConfigParser
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
cache = Cache(config={'CACHE_TYPE': 'SimpleCache'})
|
||||
db_connector = None
|
||||
conn = None
|
||||
movie_list = None
|
||||
@ -20,8 +23,9 @@ def error_decorator(fun):
|
||||
return inner1
|
||||
|
||||
@app.route("/", methods=["GET"])
|
||||
@cache.cached(timeout=69)
|
||||
def hello():
|
||||
return jsonify({"response": "Hello there"}), 200
|
||||
return jsonify({"response": "Hello there", "time": datetime.now()}), 200
|
||||
|
||||
#endpoint do wyciągania danych o userze
|
||||
@app.route("/api/v3/get/<string:username>", methods=["GET"])
|
||||
@ -59,7 +63,6 @@ def get_recommendations(oauth_ID):
|
||||
return jsonify({"movies": ["3", "Wiedźmin 3", "Najlepszy."]}), 200
|
||||
|
||||
@app.route("/api/v3/get_movie/<int:movie_ID>", methods=["GET"])
|
||||
# @error_decorator
|
||||
def get_movie(movie_ID):
|
||||
movie_info = movie_list.loc[movie_list['movie_id'] == movie_ID]
|
||||
if movie_info.empty:
|
||||
@ -136,8 +139,11 @@ if __name__ == "__main__":
|
||||
else:
|
||||
break
|
||||
|
||||
movie_list = pandas.read_csv(config["movie"]["csv_path"])
|
||||
|
||||
movie_list = pandas.read_csv(config["movie"]["csv_path"])
|
||||
cache.init_app(app)
|
||||
app.run(host="0.0.0.0",port=8090, debug=True)
|
||||
|
||||
|
||||
conn.close()
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
flask==3.0.3
|
||||
psycopg2==2.9.9
|
||||
pandas==2.2.2
|
||||
pandas==2.2.2
|
||||
Flask-Caching==2.3.0
|
||||
Loading…
Reference in New Issue
Block a user