File tree 5 files changed +581
-0
lines changed
Scripts/Miscellaneous/json2yaml
5 files changed +581
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Python script that provides the download and upload speed of your Wifi
2
+
3
+ A simple Python script that uses 'pyyaml' module to conver an input json file into a output yaml file.
4
+
5
+ ### Prerequisites
6
+
7
+ You will need to install pyyaml.
8
+ The installation commands are provided in requirements.txt
9
+
10
+ ### How to run the script
11
+
12
+ First you have to go to the json2yaml directory. Run the following command once you are in project directory
13
+
14
+ ``` bash
15
+ cd Scripts/Miscellaneous/json2yaml
16
+ ```
17
+
18
+ For Python 3:
19
+ ``` bash
20
+ python json2yaml.py jsonFilePath yamlFilePath
21
+ ```
22
+
23
+ ### Screenshot/GIF showing the sample use of the script
24
+
25
+ ![ Screenshot] ( Screenshot.png )
26
+
27
+ ## * Author Name*
28
+
29
+ David Mendoza
Original file line number Diff line number Diff line change
1
+ from json import load
2
+ from yaml import dump
3
+ from sys import argv
4
+
5
+ # validated the ammout of args passed from the command line, so I could get the path from both files before starting the script
6
+ def getInputAndOutputFiles ():
7
+ if len (argv ) == 1 :
8
+ jsonPath = input ("please enter the path to your JSON file: " )
9
+ yamlPath = input ("please enter the path to your YAML file: " )
10
+ elif len (argv ) == 2 :
11
+ jsonPath = argv [1 ]
12
+ yamlPath = input ("please enter the path to your YAML file: " )
13
+ elif len (argv ) >= 3 :
14
+ jsonPath = argv [1 ]
15
+ yamlPath = argv [2 ]
16
+ return jsonPath ,yamlPath
17
+
18
+ print ("started to convert your file..." )
19
+ jsonPath ,yamlPath = getInputAndOutputFiles ()
20
+
21
+ # from line 24 to 26
22
+ # I opened the json file
23
+ # after that I load the json string into a real python dict
24
+ def getJSONValueFromFile (jsonPath ):
25
+ with open (jsonPath , "r" ) as jsonFile :
26
+ return load (jsonFile )
27
+
28
+ if __name__ == "__main__" :
29
+ # I opened (and created if not done) the yaml destination file
30
+ # after that I dumped the dict into the yamlFile through pyyaml
31
+ # after that I closed the csv file
32
+ jsonValue = getJSONValueFromFile (jsonPath )
33
+ yamlFile = open (yamlPath , "w" )
34
+ dump (jsonValue , yamlFile )
35
+ yamlFile .close ()
36
+ print (f"done, your file is now on { yamlPath } " )
Original file line number Diff line number Diff line change
1
+ pyyaml == 5.3.1
You can’t perform that action at this time.
0 commit comments