@@ -56,19 +56,20 @@ def process_files(user:str):
5656 )
5757 print ("reseting" )
5858 # Function to read and process a file
59- def process_file (file_name ):
59+ def process_file (file_name , user1 ):
6060
6161
6262
6363 # Read file from S3
64-
65- response = s3 .get_object (Bucket = 'learnmateai' , Key = user + 'pyqs_txt/' + file_name )
64+ print ( user1 )
65+ response = s3 .get_object (Bucket = 'learnmateai' , Key = user1 + 'pyqs_txt/' + file_name )
6666 file_content = response ['Body' ].read ().decode ('utf-16-le' )
6767
6868 # Split file content into batches (adjust batch size as needed)
6969 batch_size = 30000
7070 batches = [file_content [i :i + batch_size ] for i in range (0 , len (file_content ), batch_size )]
71- response2 = s3 .get_object (Bucket = 'learnmateai' , Key = user + "syllabus_pdf/syllabus.txt" )
71+ print (user1 + "syllabus_pdf/syllabus.txt" )
72+ response2 = s3 .get_object (Bucket = 'learnmateai' , Key = user1 + "syllabus_pdf/syllabus.txt" )
7273 topics = response2 ['Body' ].read ().decode ('utf-8' )
7374 # Process batches
7475 Sorted_PYQ_Mod = [[]for _ in range (5 )]
@@ -96,7 +97,7 @@ def process_file(file_name):
9697 #print(text_batches)
9798
9899 bucket_name = 'learnmateai'
99- folder_name = 'Sorted_PYQS/'
100+ folder_name = user1 + 'Sorted_PYQS/'
100101
101102
102103 i = 0
@@ -117,7 +118,7 @@ def process_file(file_name):
117118 s3 .put_object (Bucket = bucket_name , Key = folder_name + "Module" + str (i + 1 )+ ".txt" , Body = updated_content .encode ('utf-8' ))
118119
119120 # Print uploaded file information
120- print (f"File uploaded to '{ bucket_name } /{ folder_name } '" )
121+ print (f"File uploaded to '{ user1 } { bucket_name } /{ folder_name } '" )
121122 i = i + 1
122123
123124
@@ -142,7 +143,7 @@ def process_file(file_name):
142143 s3 .put_object (Bucket = bucket_name , Key = folder_name + "Module" + str (i + 1 )+ ".txt" , Body = updated_content .encode ('utf-8' ))
143144
144145 # Print uploaded file information
145- print (f"File uploaded to '{ bucket_name } /{ folder_name } '" )
146+ print (f"File uploaded to '{ user1 } { bucket_name } /{ folder_name } '" )
146147 i = i + 1
147148 else :
148149 print ("An error occurred:" , e )
@@ -151,11 +152,13 @@ def process_file(file_name):
151152
152153
153154 # Get the list of files in the "notes_txt" folder
154- response = s3 .list_objects_v2 (Bucket = 'learnmateai' , Prefix = 'pyqs_txt/' )
155+ response = s3 .list_objects_v2 (Bucket = 'learnmateai' , Prefix = user + 'pyqs_txt/' )
155156
156157 # Process each file
157158 for file in response ['Contents' ]:
159+ print (file )
158160 file_name = file ['Key' ].split ('/' )[- 1 ]
159- process_file (file_name )
161+ print (file_name )
162+ process_file (file_name ,user )
160163
161164 return {"message" : "PYQS SORTED" }
0 commit comments