Skip to content

Commit b098e68

Browse files
committed
re-initalized the project
1 parent 15b9e8a commit b098e68

17 files changed

+113
-75
lines changed

conversion_modules/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .json_to_csv import json_toCsv
2+
from .json_to_xlsx import json_toXlsx
3+
from .mcsv_to_xlsx import Multi_csv_toXlsx
300 Bytes
Binary file not shown.
847 Bytes
Binary file not shown.
909 Bytes
Binary file not shown.
885 Bytes
Binary file not shown.

conversion_modules/json_to_csv.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import json
2+
from pandas.io.json import json_normalize
3+
import pandas
4+
5+
if __name__ == "__main__":
6+
inputjson = str(input("The JSON file path :"))
7+
outputCsv = str(input("Output CSV file :"))
8+
json_toCsv(inputjson,outputCsv)
9+
10+
def json_toCsv(input_Json_path,output_csv_path):
11+
#normalize the json
12+
if ".csv" not in output_csv_path:
13+
output_csv_path = output_csv_path + ".csv"
14+
try:
15+
with open(input_Json_path) as file:
16+
data = json.load(file)
17+
normalizedJson = json_normalize(data)
18+
normalizedJson.to_csv(output_csv_path,index=False,sep='\t',encoding='utf-8')
19+
except FileExistsError as identifier:
20+
print(identifier.errno+" Invaild path of Json")

conversion_modules/json_to_xlsx.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import json
2+
from pandas.io.json import json_normalize
3+
import pandas
4+
5+
if __name__ == "__main__":
6+
jsonpath = str(input("path to json file :"))
7+
outpath = str(input("output path of excel file :"))
8+
sheetname = str(input("enter the sheetname (optional)"))
9+
if sheetname == "":
10+
sheetname = "sheet1"
11+
json_toXlsx(jsonpath,outpath,sheetname)
12+
13+
def json_toXlsx(Json_path,output_excel,sheetname):
14+
#checking if the output has extension with it
15+
if ".xlsx" not in output_excel:
16+
output_excel = output_excel+".xlsx"
17+
#normalize the json
18+
try:
19+
with open(Json_path) as file:
20+
data = json.load(file)
21+
normalizedJson = json_normalize(data)
22+
normalizedJson.to_excel(output_excel,verbose=True,sheet_name=sheetname,encoding='utf-8')
23+
except FileNotFoundError as identifier:
24+
print("incorrect file path")

conversion_modules/mcsv_to_xlsx.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pandas import ExcelWriter
2+
import pandas
3+
4+
def Multi_csv_toXlsx(arrayOf_CSV_Filepaths,outputExcelName):
5+
if ".xlsx" not in outputExcelName:
6+
outputExcelName = outputExcelName + ".xlsx"
7+
try:
8+
with ExcelWriter(outputExcelName) as xlWriter:
9+
for CSVfile in arrayOf_CSV_Filepaths:
10+
pandas.read_csv(CSVfile).to_excel(xlWriter,sheet_name=CSVfile)
11+
except FileExistsError as identifier:
12+
print("incorrect file name")
13+
print("successfully converted to Excel at "+outputExcelName)
14+
15+
if __name__ == "__main__":
16+
no_of_csv_files = int(input("Number of csv files to be added :"))
17+
list_of_csv_files = []
18+
for iterator in range(no_of_csv_files):
19+
filename = str(input("CSV File "+(iterator+1)+" Path :"))
20+
list_of_csv_files.append(filename)
21+
outputExcelfilename = str(input("Output Excel file name :"))
22+
Multi_csv_toXlsx(list_of_csv_files,outputExcelfilename)

dummy.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name":"Mr.Meekseeks",
3+
"age":20,
4+
"date of birth":"08/05/1999",
5+
"skills":{
6+
"skill1":"sleeping",
7+
"skill1_percentage":"90%",
8+
"skill1_disadvandage":"causes plague"
9+
}
10+
}

exported_json.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)