Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hard dependency on simplejson in getBroadlinkSharedData.py #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 35 additions & 4 deletions getBroadlinkSharedData.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,40 @@

'''

import simplejson as json
import base64, sys

try:
# Python 2.6+
import json
except ImportError:
try:
# from http://code.google.com/p/simplejson
import simplejson as json
except ImportError:
json = None

if json is None:

def dump_json(x, indent=None):
"""dumb not safe!
Works for the purposes of this specific script as quotes never
appear in data set.

Parameter indent ignored"""
if indent:
result = pprint.pformat(x, indent)
else:
result = repr(x).replace("'", '"')
return result

def load_json(x):
"""dumb not safe! Works for the purposes of this specific script"""
x = x.replace('\r', '')
return eval(x)
else:
dump_json = json.dumps
load_json = json.loads


if len(sys.argv) > 1:
MultipleCode = sys.argv[1]
Expand All @@ -36,7 +67,7 @@


jsonSubIr = open("jsonSubIr").read()
jsonSubIrData = json.loads(jsonSubIr)
jsonSubIrData = load_json(jsonSubIr)


for i in range(0, len(jsonSubIrData)):
Expand All @@ -52,7 +83,7 @@


jsonButton = open("jsonButton").read()
jsonButtonData = json.loads(jsonButton)
jsonButtonData = load_json(jsonButton)


for i in range(0, len(jsonButtonData)):
Expand All @@ -62,7 +93,7 @@


jsonIrCode = open("jsonIrCode").read()
jsonIrCodeData = json.loads(jsonIrCode)
jsonIrCodeData = load_json(jsonIrCode)


print "[+] Dumping codes to " + accessory_name + ".txt"
Expand Down