Skip to content

Commit 71f669f

Browse files
committed
Initial commit
1 parent e8082ce commit 71f669f

File tree

8 files changed

+173
-2
lines changed

8 files changed

+173
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ __pycache__/
1010
.Python
1111
build/
1212
develop-eggs/
13-
dist/
13+
#dist/
1414
downloads/
1515
eggs/
1616
.eggs/
@@ -31,7 +31,7 @@ MANIFEST
3131
# Usually these files are written by a python script from a template
3232
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3333
*.manifest
34-
*.spec
34+
#*.spec
3535

3636
# Installer logs
3737
pip-log.txt

car-models.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Brand,Model
2+
BMW,M135i xDrive
3+
Mercedes-Benz,GLA 250
4+
Proton,X70
5+
Perodua,Ativa 1.0
6+
Honda,Civic 1.5
7+
Toyota,Rush 1.5
8+
Ferrari,458 Italia
9+
Bugatti,Chiron Super Sport
10+
Produa,Aruz 1.5
11+
Honda,City 1.5

csvtojson-1652043963.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"Brand": "BMW",
4+
"Model": "M135i xDrive"
5+
},
6+
{
7+
"Brand": "Mercedes-Benz",
8+
"Model": "GLA 250"
9+
},
10+
{
11+
"Brand": "Proton",
12+
"Model": "X70"
13+
},
14+
{
15+
"Brand": "Perodua",
16+
"Model": "Ativa 1.0"
17+
},
18+
{
19+
"Brand": "Honda",
20+
"Model": "Civic 1.5"
21+
},
22+
{
23+
"Brand": "Toyota",
24+
"Model": "Rush 1.5"
25+
},
26+
{
27+
"Brand": "Ferrari",
28+
"Model": "458 Italia"
29+
},
30+
{
31+
"Brand": "Bugatti",
32+
"Model": "Chiron Super Sport"
33+
},
34+
{
35+
"Brand": "Produa",
36+
"Model": "Aruz 1.5"
37+
},
38+
{
39+
"Brand": "Honda",
40+
"Model": "City 1.5"
41+
}
42+
]

dist/py-csv-json-cli.exe

7.39 MB
Binary file not shown.

jsontocsv-1652043976.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Brand,Model
2+
BMW,M135i xDrive
3+
Mercedes-Benz,GLA 250
4+
Proton,X70
5+
Perodua,Ativa 1.0
6+
Honda,Civic 1.5
7+
Toyota,Rush 1.5
8+
Ferrari,458 Italia
9+
Bugatti,Chiron Super Sport
10+
Produa,Aruz 1.5
11+
Honda,City 1.5

py-csv-json-cli.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import fire
2+
3+
class ConvertCsvJson(object):
4+
5+
def __init__(self):
6+
import datetime
7+
8+
curr_dt = datetime.datetime.now()
9+
self._timestamp = int(round(curr_dt.timestamp()))
10+
11+
12+
def jsontocsv(self,jsonFilePath):
13+
import csv
14+
import json
15+
16+
if not jsonFilePath.endswith('.json'):
17+
return "Error: Invalid JSON file!"
18+
19+
csvOutputFile = "jsontocsv-{timestamp}.csv".format(timestamp=self._timestamp)
20+
21+
with open(jsonFilePath) as jsonf:
22+
jsondata = json.load(jsonf)
23+
24+
data_file = open(csvOutputFile, 'w', newline='')
25+
csv_writer = csv.writer(data_file)
26+
27+
count = 0
28+
for data in jsondata:
29+
30+
if count == 0:
31+
header = data.keys()
32+
csv_writer.writerow(header)
33+
count += 1
34+
csv_writer.writerow(data.values())
35+
36+
data_file.close()
37+
38+
return "Successfully created {output}".format(output=csvOutputFile)
39+
40+
41+
def csvtojson(self,csvFilePath):
42+
import csv
43+
import json
44+
45+
if not csvFilePath.endswith('.csv'):
46+
return "Error: Invalid CSV file!"
47+
48+
jsonOutputFile = "csvtojson-{timestamp}.json".format(timestamp=self._timestamp)
49+
data = []
50+
51+
with open(csvFilePath, encoding='utf-8') as csvf:
52+
csvReader = csv.DictReader(csvf)
53+
for rows in csvReader:
54+
data.append(rows)
55+
56+
with open(jsonOutputFile, 'a', encoding='utf-8') as jsonf:
57+
jsonf.write(json.dumps(data, indent=4))
58+
59+
return "Successfully created {output}".format(output=jsonOutputFile)
60+
61+
62+
if __name__ == '__main__':
63+
fire.Fire(ConvertCsvJson)

py-csv-json-cli.spec

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
block_cipher = None
5+
6+
7+
a = Analysis(
8+
['py-csv-json-cli.py'],
9+
pathex=[],
10+
binaries=[],
11+
datas=[],
12+
hiddenimports=[],
13+
hookspath=[],
14+
hooksconfig={},
15+
runtime_hooks=[],
16+
excludes=[],
17+
win_no_prefer_redirects=False,
18+
win_private_assemblies=False,
19+
cipher=block_cipher,
20+
noarchive=False,
21+
)
22+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
23+
24+
exe = EXE(
25+
pyz,
26+
a.scripts,
27+
a.binaries,
28+
a.zipfiles,
29+
a.datas,
30+
[],
31+
name='py-csv-json-cli',
32+
debug=False,
33+
bootloader_ignore_signals=False,
34+
strip=False,
35+
upx=True,
36+
upx_exclude=[],
37+
runtime_tmpdir=None,
38+
console=True,
39+
disable_windowed_traceback=False,
40+
argv_emulation=False,
41+
target_arch=None,
42+
codesign_identity=None,
43+
entitlements_file=None,
44+
)

requirements.txt

350 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)