mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-27 14:01:09 +00:00
Csv_to_json (#224)
* Added csv_to_json script * added requirements.txt file * added images * Added README.md * Added my details
This commit is contained in:
parent
fdbeacccd0
commit
45dd094afc
|
@ -181,7 +181,8 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Image Compressor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image_Compressor)|[Prathima Kadari](https://github.com/prathimacode-hub)|
|
|[Image Compressor](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Image_Compressor)|[Prathima Kadari](https://github.com/prathimacode-hub)|
|
||||||
|[Test Your Internet Speed](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TestMyInternetSpeed)|[TheSmartDeveloperr](https://github.com/thesmartdeveloperr)|
|
|[Test Your Internet Speed](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TestMyInternetSpeed)|[TheSmartDeveloperr](https://github.com/thesmartdeveloperr)|
|
||||||
|[Plagiarism_detector](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Plagiarism_detector)|[Akshita Singhal](https://github.com/akshitasinghal4444)|
|
|[Plagiarism_detector](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Plagiarism_detector)|[Akshita Singhal](https://github.com/akshitasinghal4444)|
|
||||||
|[Battery_notification](https://github.com/hastagABAwesome-Python-Scripts/Battery_notification/)|[Krishna Sharma](https://github.com/krishnasharma1386)
|
|[csv_to_json](https://github.com/TechBoyy6/Awesome-Python-Scripts/tree/CSVtoJSON/csv_to_json)|[MoiZ](https://github.com/TechBoyy6)|
|
||||||
|
|[Battery_notification](https://github.com/hastagABAwesome-Python-Scripts/Battery_notification/)|[Krishna Sharma](https://github.com/krishnasharma1386)|
|
||||||
|
|
||||||
## How to use :
|
## How to use :
|
||||||
|
|
||||||
|
|
9
csv_to_json/README.md
Normal file
9
csv_to_json/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# PyRecorder
|
||||||
|
A python script that converts the csv file into json
|
||||||
|
## CLI interface
|
||||||
|
![image](https://github.com/TechBoyy6/Awesome-Python-Scripts/blob/CSVtoJSON/csv_to_json/img/CLI.jpg)
|
||||||
|
## Files
|
||||||
|
before<br/>
|
||||||
|
![before](https://github.com/TechBoyy6/Awesome-Python-Scripts/blob/CSVtoJSON/csv_to_json/img/before.jpg)<br/>
|
||||||
|
After<br/>
|
||||||
|
![after](https://github.com/TechBoyy6/Awesome-Python-Scripts/blob/CSVtoJSON/csv_to_json/img/after.jpg)
|
32
csv_to_json/convert.py
Normal file
32
csv_to_json/convert.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
|
||||||
|
file_name = input("Provide the CSV filename without extension>> ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
with open(file_name+'.csv') as f:
|
||||||
|
|
||||||
|
reader = csv.reader(f, delimiter=',')
|
||||||
|
titles = []
|
||||||
|
temp_data = {}
|
||||||
|
|
||||||
|
for heading in reader:
|
||||||
|
titles = heading
|
||||||
|
break
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
for row in reader:
|
||||||
|
current_row = "row{}".format(i)
|
||||||
|
temp_data['{}'.format(current_row)] = {}
|
||||||
|
for col in range(len(titles)):
|
||||||
|
temp_data[current_row][titles[col]] = row[col]
|
||||||
|
i+=1
|
||||||
|
|
||||||
|
with open(file_name+'.json', 'w') as f_j:
|
||||||
|
json.dump(temp_data, f_j, indent=4)
|
||||||
|
|
||||||
|
except:
|
||||||
|
print("Please provide correct filename")
|
||||||
|
|
||||||
|
print("File converted successfully :)")
|
BIN
csv_to_json/img/CLI.jpg
Normal file
BIN
csv_to_json/img/CLI.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
csv_to_json/img/after.jpg
Normal file
BIN
csv_to_json/img/after.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
csv_to_json/img/before.jpg
Normal file
BIN
csv_to_json/img/before.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
2
csv_to_json/requirements.txt
Normal file
2
csv_to_json/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
csv
|
||||||
|
json
|
Loading…
Reference in New Issue
Block a user