added json to yaml script

This commit is contained in:
Michael Herman 2015-10-11 09:28:50 -06:00
parent b287df6e18
commit 24d6113bd7
4 changed files with 51 additions and 11 deletions

31
29_json_test.json Normal file
View File

@ -0,0 +1,31 @@
{
"colorsArray":[{
"colorName":"red",
"hexValue":"#f00"
},
{
"colorName":"green",
"hexValue":"#0f0"
},
{
"colorName":"blue",
"hexValue":"#00f"
},
{
"colorName":"cyan",
"hexValue":"#0ff"
},
{
"colorName":"magenta",
"hexValue":"#f0f"
},
{
"colorName":"yellow",
"hexValue":"#ff0"
},
{
"colorName":"black",
"hexValue":"#000"
}
]
}

16
29_json_to_yaml.py Normal file
View File

@ -0,0 +1,16 @@
import sys
import json
import yaml
"""
Example usage:
$ python 29_json_to_yaml.py 29_json_test.json
"""
# load json data
json_data = json.loads(open(sys.argv[1]).read())
# convert unicode to string
converted_json_data = json.dumps(json_data)
# output yaml
print(yaml.dump(yaml.load(converted_json_data), default_flow_style=False))

View File

@ -4,7 +4,7 @@
1. **02_find_all_links.py**: get all links from a webpage
1. **03_simple_twitter_manager.py**: accessing the Twitter API, example functions
1. **04_rename_with_slice.py**: rename group of files, within a single directory, using slice
1. **05_load_json_without_dupes.py**: load json, convert to dict, raise error if there is a duplicate key
1. **05_load_json_without_dupes.py**: load JSON, convert to dict, raise error if there is a duplicate key
1. **06_execution_time.py**: class used for timing execution of code
1. **07_benchmark_permissions_loading_django.py**: benchmark loading of permissions in Django
1. **08_basic_email_web_crawler.py**: web crawler for grabbing emails from a website
@ -27,4 +27,5 @@
1. **25_ip2geolocation.py**: Given a CSV file with an ip address (see sample - *25_sample_csv.csv*), return the geolocation based on the ip.
1. **26_stock_scraper.py**: Scrape the S&P 500 Companies list from Wikipedia, then output the data.
1. **27_send_sms.py**: Send SMS message via [TextBelt](http://textbelt.com/)
1. **28_income_tax_calculator.py**: Income tax calcuator via [Taxee](http://taxee.io/)
1. **28_income_tax_calculator.py**: Income tax calculator via [Taxee](http://taxee.io/)
1. **29_json_to_yaml.py**: Convert JSON to YAML

View File

@ -1,11 +1,3 @@
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Wand==0.4.0
Werkzeug==0.10.4
hurry.filesize==0.9
itsdangerous==0.24
lxml==3.4.4
numpy==1.9.2
PyYAML==3.11
requests==2.7.0
wheel==0.24.0