Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Scripts/Miscellaneous/json2yaml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Python script that provides the download and upload speed of your Wifi

A simple Python script that uses 'pyyaml' module to conver an input json file into a output yaml file.

### Prerequisites

You will need to install pyyaml.
The installation commands are provided in requirements.txt

### How to run the script

First you have to go to the json2yaml directory. Run the following command once you are in project directory

```bash
cd Scripts/Miscellaneous/json2yaml
```

For Python 3:
```bash
python json2yaml.py jsonFilePath yamlFilePath
```

### Screenshot/GIF showing the sample use of the script

![Screenshot](Screenshot.png)

## *Author Name*

David Mendoza
Binary file added Scripts/Miscellaneous/json2yaml/Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions Scripts/Miscellaneous/json2yaml/json2yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from json import load
from yaml import dump
from sys import argv

# validated the ammout of args passed from the command line, so I could get the path from both files before starting the script
def getInputAndOutputFiles():
if len(argv) ==1:
jsonPath = input("please enter the path to your JSON file: ")
yamlPath = input("please enter the path to your YAML file: ")
elif len(argv) == 2:
jsonPath = argv[1]
yamlPath = input("please enter the path to your YAML file: ")
elif len(argv) >= 3:
jsonPath = argv[1]
yamlPath = argv[2]
return jsonPath,yamlPath

print("started to convert your file...")
jsonPath,yamlPath = getInputAndOutputFiles()

# from line 24 to 26
# I opened the json file
# after that I load the json string into a real python dict
def getJSONValueFromFile(jsonPath):
with open(jsonPath, "r") as jsonFile:
return load(jsonFile)

if __name__ == "__main__":
# I opened (and created if not done) the yaml destination file
# after that I dumped the dict into the yamlFile through pyyaml
# after that I closed the csv file
jsonValue = getJSONValueFromFile(jsonPath)
yamlFile = open(yamlPath, "w")
dump(jsonValue, yamlFile)
yamlFile.close()
print(f"done, your file is now on {yamlPath}")
1 change: 1 addition & 0 deletions Scripts/Miscellaneous/json2yaml/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyaml==5.3.1
Loading