diff --git a/cloud_storage/cloud.py b/cloud_storage/cloud.py index dd42b47..68befb2 100644 --- a/cloud_storage/cloud.py +++ b/cloud_storage/cloud.py @@ -75,3 +75,21 @@ def upload_to_cloud(self, blob_Path, local_Path, file_Name): bucketName = config.get("ORACLE", "bucket_name") ) oracle_service.upload_files(bucketPath = blob_Path, localPath = local_Path, fileName = file_Name) + + def upload_to_NVSK_cloud(self, blob_Path, local_Path, file_Name,customBucket = False): + ''' + Function to upload the file to respective cloud based on the available section in the config file + + :param: blob_Path - The path where the file would be stored in the cloud + :param: local_Path - The path where the file is in the local server + :param: file_Name - The name of the file that is being updated + ''' + + oracle_service = Oracle( + regionName = config.get("ORACLE", "region_name"), + accessKey = config.get("ORACLE", "access_key"), + secretAccessKey = config.get("ORACLE", "secret_access_key"), + endpoint_url = config.get("ORACLE", "endpoint_url"), + bucketName = "dev-diksha-privatereports" + ) + oracle_service.upload_files(bucketPath = blob_Path, localPath = local_Path, fileName = file_Name) \ No newline at end of file diff --git a/urgent_data_metrics/imp_project_metrics.py b/urgent_data_metrics/imp_project_metrics.py index 4ba4438..837fb3c 100644 --- a/urgent_data_metrics/imp_project_metrics.py +++ b/urgent_data_metrics/imp_project_metrics.py @@ -6,7 +6,7 @@ # entity information # ----------------------------------------------------------------- -import json, sys, time +import json, sys, time , csv from configparser import ConfigParser,ExtendedInterpolation from pymongo import MongoClient from bson.objectid import ObjectId @@ -347,5 +347,35 @@ def searchEntities(url,ids_list): os.rename(f'{path}' + f'{result[0]}', f'{path}' + 'data.csv') # Uploading file to Cloud cloud_init.upload_to_cloud(blob_Path = blob_path, local_Path = local_path, file_Name = 'data.csv') + +json_keys = ["state_name","district_name","Total_Micro_Improvement_Projects","Total_Micro_Improvement_Started","Total_Micro_Improvement_InProgress","Total_Micro_Improvement_Submitted","Total_Micro_Improvement_Submitted_With_Evidence"] +jsonTableData = [] +# Open the CSV file +with open(os.path.join(local_path,'data.csv'), 'r') as file: + # Create a CSV reader object + csv_reader = csv.reader(file) + + # Skip the header row + next(csv_reader) + + for row in csv_reader: + jsonTableData.append(row) + +final_json = { + 'keys' : json_keys, + 'tableData' : jsonTableData +} + +# Open the Json file +with open(os.path.join(local_path,'micro_improvement.json'), 'w') as json_file: + json.dump(final_json, json_file, indent=2) + +os.rename(os.path.join(local_path,'data.csv'), f'{local_path}' + 'micro_improvement.csv') +# Uploading file to Cloud +cloud_init.upload_to_NVSK_cloud(blob_Path = "Manage_Learn_Data/micro_improvement", local_Path = local_path, file_Name = 'micro_improvement.json') + +cloud_init.upload_to_NVSK_cloud(blob_Path = "Manage_Learn_Data/micro_improvement", local_Path = local_path, file_Name = 'micro_improvement.csv') + + print("file got uploaded to Cloud.") print("DONE") \ No newline at end of file