mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-27 14:01:12 +00:00
Merge pull request #316 from SiddheshKukade/master
Feature : JSON to YAML file Converter
This commit is contained in:
commit
3427da871d
44
README.md
44
README.md
|
@ -238,13 +238,28 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<sub><b>YUNGH OG</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/SiddheshKukade">
|
||||
<img src="https://avatars.githubusercontent.com/u/65951872?v=4" width="100;" alt="SiddheshKukade"/>
|
||||
<br />
|
||||
<sub><b>Siddhesh Bhupendra Kuakde</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/varunKT001">
|
||||
<img src="https://avatars.githubusercontent.com/u/83509023?v=4" width="100;" alt="varunKT001"/>
|
||||
<br />
|
||||
<sub><b>Varun Tiwari</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/avyayjain">
|
||||
<img src="https://avatars.githubusercontent.com/u/63355322?v=4" width="100;" alt="avyayjain"/>
|
||||
<br />
|
||||
<sub><b>Avyay Jain</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://github.com/drk1rd">
|
||||
<img src="https://avatars.githubusercontent.com/u/58465650?v=4" width="100;" alt="drk1rd"/>
|
||||
|
@ -258,8 +273,7 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<br />
|
||||
<sub><b>Null</b></sub>
|
||||
</a>
|
||||
</td></tr>
|
||||
<tr>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/rohitgarud21">
|
||||
<img src="https://avatars.githubusercontent.com/u/115347445?v=4" width="100;" alt="rohitgarud21"/>
|
||||
|
@ -287,7 +301,8 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<br />
|
||||
<sub><b>Srinjoy Pati</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://github.com/Shradha-Suman">
|
||||
<img src="https://avatars.githubusercontent.com/u/103067896?v=4" width="100;" alt="Shradha-Suman"/>
|
||||
|
@ -301,8 +316,7 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<br />
|
||||
<sub><b>Nishant Pacharne</b></sub>
|
||||
</a>
|
||||
</td></tr>
|
||||
<tr>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/thegeekyb0y">
|
||||
<img src="https://avatars.githubusercontent.com/u/84658112?v=4" width="100;" alt="thegeekyb0y"/>
|
||||
|
@ -330,7 +344,8 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<br />
|
||||
<sub><b>Mayuri Kolhe</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://github.com/parinzee">
|
||||
<img src="https://avatars.githubusercontent.com/u/30139280?v=4" width="100;" alt="parinzee"/>
|
||||
|
@ -344,21 +359,6 @@ Thanks a lot for spending your time helping! Keep rocking 🍻
|
|||
<br />
|
||||
<sub><b>Sayan Roy</b></sub>
|
||||
</a>
|
||||
</td></tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="https://github.com/SiddheshKukade">
|
||||
<img src="https://avatars.githubusercontent.com/u/65951872?v=4" width="100;" alt="SiddheshKukade"/>
|
||||
<br />
|
||||
<sub><b>Siddhesh Bhupendra Kuakde</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/varunKT001">
|
||||
<img src="https://avatars.githubusercontent.com/u/83509023?v=4" width="100;" alt="varunKT001"/>
|
||||
<br />
|
||||
<sub><b>Varun Tiwari</b></sub>
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
<a href="https://github.com/ambushneupane">
|
||||
|
|
4
scripts/JSON-to-YAML Converter/README.md
Normal file
4
scripts/JSON-to-YAML Converter/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
### JSON to YAML file converter
|
||||
Takes JSON data and converts it into YAML file by braking the JSON array and using the YAML library of python
|
||||
### To Execute the code
|
||||
`json2yaml.py input_file.json output_file.yaml`
|
35
scripts/JSON-to-YAML Converter/json2yaml.py
Normal file
35
scripts/JSON-to-YAML Converter/json2yaml.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
|
||||
# Checking there is a file name passed
|
||||
if len(sys.argv) > 1:
|
||||
# Opening the file
|
||||
if os.path.exists(sys.argv[1]):
|
||||
source_file = open(sys.argv[1], "r")
|
||||
source_content = json.load(source_file)
|
||||
source_file.close()
|
||||
# Failikng if the file isn't found
|
||||
else:
|
||||
print("ERROR: " + sys.argv[1] + " not found")
|
||||
exit(1)
|
||||
# No file, no usage
|
||||
else:
|
||||
print("Usage: json2yaml.py <source_file.json> [target_file.yaml]")
|
||||
|
||||
# Processing the conversion
|
||||
output = yaml.dump(source_content)
|
||||
|
||||
# If no target file send to stdout
|
||||
if len(sys.argv) < 3:
|
||||
print(output)
|
||||
# If the target file already exists exit
|
||||
elif os.path.exists(sys.argv[2]):
|
||||
print("ERROR: " + sys.argv[2] + " already exists")
|
||||
exit(1)
|
||||
# Otherwise write to the specified file
|
||||
else:
|
||||
target_file = open(sys.argv[2], "w")
|
||||
target_file.write(output)
|
||||
target_file.close()
|
Loading…
Reference in New Issue
Block a user