From d3ff36876e302d5d09f3453c1f7c1a7579c009c8 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 16 Dec 2024 23:47:11 +0100 Subject: [PATCH] puuuush ctime and mtime added to Mongo DB; Seems to work lol --- lib.py | 2 +- main.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib.py b/lib.py index 81cdaf7..d65f145 100644 --- a/lib.py +++ b/lib.py @@ -107,6 +107,6 @@ def get_data_from_mongo(dataset): for set in dataset: json_data = collection.find_one({"doc_id": set[0]}) - result_string += "Dateipfad: " + json_data["filepath"] + "; Inhalt: " + json_data["chunk_content"] + "; " + result_string += "Dateipfad: " + json_data["filepath"] + "; Inhalt: " + json_data["chunk_content"] + "; Erstellungszeitpunkt: " + json_data["ctime"] + "; Letzte Bearbeitung: " + json_data["mtime"] return result_string \ No newline at end of file diff --git a/main.py b/main.py index 5e3bf1e..4f0b558 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ import lib import json import psycopg2 import pymongo - +from datetime import datetime import mongo_conn import pgvec_conn import redis_conn @@ -40,16 +40,24 @@ def retrieve_file_contents(path, pPullFromS3): lib.read_files(path, files := []) contents = [] + ctime = "" + mtime = "" print("parsing files...") for file in tqdm(files): + if not pPullFromS3: + ctime = datetime.fromtimestamp(os.path.getctime(file[1])).strftime('%Y-%m-%d %H:%M:%S') + mtime = datetime.fromtimestamp(os.path.getmtime(file[1])).strftime('%Y-%m-%d %H:%M:%S') + print(ctime, mtime) content = file_extraction_functions[file[0]](file[1]) if not pPullFromS3: push_files_into_s3(file, content, minioClient) contents.append({ "type": file[0], - "path": file[1] if not pPullFromS3 else "Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ", + "ctime": ctime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ', + "mtime": mtime if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ', + "path": file[1] if not pPullFromS3 else 'Diese Datei kommt ursprünglich nicht von dir, sondern aus einem S3-Bucket. ', "filename": file[2], "content": content }) @@ -96,16 +104,18 @@ def create_embeddings(pContent): insert_data = f"insert into dbtable (filepath, embedding) Values ('{content['path']}', %s) Returning id;" cur.execute(insert_data, (response["embedding"],)) doc_id = cur.fetchone()[0] - insert_data_mongo(doc_id, content['path'], chunk) + insert_data_mongo(doc_id, content['path'], chunk, content['ctime'], content["mtime"]) conn.commit() conn.close() -def insert_data_mongo(id, filepath,pChunk): +def insert_data_mongo(id, filepath,pChunk, pCtime, pMtime): client = pymongo.MongoClient('mongodb://python:PasswordPassword123@localhost:27017/') mongodb = client['document_table'] collection = mongodb['documents'] dokument = { 'doc_id': id, + 'ctime' : pCtime, + 'mtime' : pMtime, 'filepath': filepath, 'chunk_content': pChunk, }