diff --git a/README.md b/README.md index 88bbb99..ca3c33c 100644 --- a/README.md +++ b/README.md @@ -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)| |[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)| -|[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 : diff --git a/csv_to_json/README.md b/csv_to_json/README.md new file mode 100644 index 0000000..55e958d --- /dev/null +++ b/csv_to_json/README.md @@ -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
+![before](https://github.com/TechBoyy6/Awesome-Python-Scripts/blob/CSVtoJSON/csv_to_json/img/before.jpg)
+After
+![after](https://github.com/TechBoyy6/Awesome-Python-Scripts/blob/CSVtoJSON/csv_to_json/img/after.jpg) diff --git a/csv_to_json/convert.py b/csv_to_json/convert.py new file mode 100644 index 0000000..20899d8 --- /dev/null +++ b/csv_to_json/convert.py @@ -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 :)") \ No newline at end of file diff --git a/csv_to_json/img/CLI.jpg b/csv_to_json/img/CLI.jpg new file mode 100644 index 0000000..c13467a Binary files /dev/null and b/csv_to_json/img/CLI.jpg differ diff --git a/csv_to_json/img/after.jpg b/csv_to_json/img/after.jpg new file mode 100644 index 0000000..632e229 Binary files /dev/null and b/csv_to_json/img/after.jpg differ diff --git a/csv_to_json/img/before.jpg b/csv_to_json/img/before.jpg new file mode 100644 index 0000000..a498d6d Binary files /dev/null and b/csv_to_json/img/before.jpg differ diff --git a/csv_to_json/requirements.txt b/csv_to_json/requirements.txt new file mode 100644 index 0000000..fb1b0b3 --- /dev/null +++ b/csv_to_json/requirements.txt @@ -0,0 +1,2 @@ +csv +json \ No newline at end of file