Skip to content

Commit

Permalink
Merge pull request #170 from shikshalokam/release-5.1.0
Browse files Browse the repository at this point in the history
NVSK generate json from CSV
  • Loading branch information
aks30 authored Jan 12, 2024
2 parents a15fdd6 + e65b5af commit b22d2d6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
18 changes: 18 additions & 0 deletions cloud_storage/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
32 changes: 31 additions & 1 deletion urgent_data_metrics/imp_project_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

0 comments on commit b22d2d6

Please sign in to comment.