-
-
Save Tonyliu2ca/7ad88c039001cb793efb9736b9dad89e to your computer and use it in GitHub Desktop.
Convert between JSON and Plist Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import plistlib | |
import json | |
import tkFileDialog | |
import re | |
import sys | |
file_to_open = tkFileDialog.askopenfilename(message="Select an existing plist or json file to convert.") | |
converted = None | |
if file_to_open.endswith('json'): | |
converted = "plist" | |
converted_dict = json.load(open(file_to_open)) | |
file_to_write = tkFileDialog.asksaveasfilename(message="Select a filename to save the converted file.", | |
defaultextension = converted) | |
plistlib.writePlist(converted_dict, file_to_write) | |
elif file_to_open.endswith('plist'): | |
converted = "json" | |
converted_dict = plistlib.readPlist(file_to_open) | |
converted_string = json.dumps(converted_dict, sort_keys=True, indent=4) | |
file_to_write = tkFileDialog.asksaveasfilename(message="Select a filename to save the converted file.", | |
defaultextension = converted) | |
open(file_to_write, 'w').write(converted_string) | |
else: | |
print("WHAT THE F*** ARE YOU TRYING TO DO??????") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment