11import uvicorn
22from fastapi import FastAPI
33from fastapi import APIRouter
4+ import PyPDF2
5+ import base64
46import boto3
5-
7+ import json
68
79aws_access_key_id = 'AKIAZTHHIOR4JJ5HLTUB'
810aws_secret_access_key = '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'
1517getfiles = APIRouter ()
1618
1719@getfiles .post ("/get_notes_txt" )
18- async def retrieve_files (email : str ):
20+ async def retrieve_text_notes (email : str ):
1921 # Configure your AWS credentials and region
2022
2123
@@ -36,7 +38,7 @@ async def retrieve_files(email: str):
3638 return {"files" : files }
3739
3840@getfiles .post ("/get_notes_pdf" )
39- async def retrieve_files (email : str ):
41+ async def retrieve_pdf_files (email : str ):
4042 # Configure your AWS credentials and region
4143
4244
@@ -51,7 +53,25 @@ async def retrieve_files(email: str):
5153 for obj in response ["Contents" ]:
5254 file_key = obj ["Key" ]
5355 file_obj = s3_client .get_object (Bucket = bucket_name , Key = file_key )
54- file_content = file_obj ["Body" ].read ().decode ("utf-8" )
55- files .append ({"name" : file_key , "content" : file_content })
56+ file_content = file_obj ["Body" ].read ()
57+
58+ # Encode the file content in base64
59+ encoded_content = base64 .b64encode (file_content ).decode ("utf-8" )
60+ files .append ({"name" : file_key , "content" : encoded_content })
61+
62+ return {"files" : files }
63+
64+ @getfiles .post ("/cardData" )
65+ def get_cardData (email : str ):
66+ prefix = f"{ email } /Cardjson"
5667
57- return {"files" : files }
68+ response = s3_client .list_objects_v2 (Bucket = bucket_name , Prefix = prefix )
69+
70+
71+ if "Contents" in response :
72+ for obj in response ["Contents" ]:
73+ file_key = obj ["Key" ]
74+ file_obj = s3_client .get_object (Bucket = bucket_name , Key = file_key )
75+ file_content = file_obj ["Body" ].read ().decode ("utf-8" )
76+ json_data = json .loads (file_content )
77+ return json_data
0 commit comments