diff --git a/server/src/handlers/db_handler.py b/server/src/handlers/db_handler.py index fc5dfd05..afb8c0dd 100644 --- a/server/src/handlers/db_handler.py +++ b/server/src/handlers/db_handler.py @@ -1,37 +1,35 @@ -"""Handler for the database""" -import json +# """Handler for the database""" +# import json -from dotenv.main import load_dotenv -from pymongo import MongoClient +# from dotenv.main import load_dotenv +# from pymongo import MongoClient -# Getting the connection string -load_dotenv() +# # Getting the connection string +# load_dotenv() # pylint ignore next line naming and line length -# pylint: disable=C0103, C0301 -connection_string = "mongodb+srv://lifelineteamdb:mypassword1@cluster0.ib2qbgg.mongodb.net/?retryWrites=true&w=majority" -# Defining a MongoDB client instance -client = MongoClient(connection_string) +# # Defining a MongoDB client instance +# client = MongoClient(connection_string) -# DB name -db = client["database1"] +# # DB name +# db = client["database1"] -# Referencing the collection -courses = db["courses"] +# # Referencing the collection +# courses = db["courses"] -def insert_course_into_db(sha: str, course_str: str): - """Inserts a course into the database""" - course = {"sha": sha, "course_str": course_str} - result = courses.insert_one(course) - print("Course inserted with ID:", result.inserted_id) +# def insert_course_into_db(sha: str, course_str: str): +# """Inserts a course into the database""" +# course = {"sha": sha, "course_str": course_str} +# result = courses.insert_one(course) +# print("Course inserted with ID:", result.inserted_id) -def query_course_from_db(sha: str): - """Queries the database for a course with the given sha""" - course = courses.find_one({"sha": sha}) - if course: - print("Found a cached course with ID:", course["_id"]) - return json.loads(course["course_str"]) - print("Didn't find a cached course") - return None +# def query_course_from_db(sha: str): +# """Queries the database for a course with the given sha""" +# course = courses.find_one({"sha": sha}) +# if course: +# print("Found a cached course with ID:", course["_id"]) +# return json.loads(course["course_str"]) +# print("Didn't find a cached course") +# return None diff --git a/server/src/handlers/file_handler.py b/server/src/handlers/file_handler.py index a4c08b2f..09d5492d 100644 --- a/server/src/handlers/file_handler.py +++ b/server/src/handlers/file_handler.py @@ -16,7 +16,7 @@ from pdfminer.pdfparser import PDFSyntaxError from .openai_api_handler import get_assessments_from_text -from .db_handler import insert_course_into_db, query_course_from_db +# from .db_handler import insert_course_into_db, query_course_from_db def handle_file(file: UploadFile, response: Response, premium: bool = False): """Handles one file""" @@ -24,17 +24,17 @@ def handle_file(file: UploadFile, response: Response, premium: bool = False): tmp_path = save_temp_file(file) print(f"Processing file: {tmp_path}") - print("First checking if a cached version of the course is present") - file_hash = get_file_hash(tmp_path) - print(f"The file hash is: {file_hash}") + # print("First checking if a cached version of the course is present") + # file_hash = get_file_hash(tmp_path) + # print(f"The file hash is: {file_hash}") - print("Querying the DB") - cached_course = query_course_from_db(file_hash) - if cached_course is not None: - print("Found cached course for this file hash. Returning it.") - return cached_course + # print("Querying the DB") + # cached_course = query_course_from_db(file_hash) + # if cached_course is not None: + # print("Found cached course for this file hash. Returning it.") + # return cached_course - print("Couldn't find a cached version. Processing the file as usual.") + # print("Couldn't find a cached version. Processing the file as usual.") # Processing only if we don't have a cached version available with pdfplumber.open(tmp_path) as pdf: course = get_course_info(pdf) @@ -54,8 +54,8 @@ def handle_file(file: UploadFile, response: Response, premium: bool = False): if tmp_path: tmp_path.unlink() - print("Caching the course for future use") - insert_course_into_db(file_hash, json.dumps(course)) + # print("Caching the course for future use") + # insert_course_into_db(file_hash, json.dumps(course)) return course