Commits

Ed Brannin committed f6f14ea Draft

Transforming the Springboard JSON to d3 JSON

  • Participants
  • Parent commits 8a9b353

Comments (0)

Files changed (1)

springboard_to_d3.py

+import json
+import pprint
+
+def process_node(name, node):
+  answer = list()
+  #print "node is: %s" % node
+  for item in node:
+    #print "    item is %s" % item
+    if isinstance(item, dict):
+      # print "    Folder: %s" % item["iconLists"]
+      if len(item["iconLists"]) == 1:
+        answer.append(process_node(item["displayName"], item["iconLists"][0]))
+      elif len(item["iconLists"]) == 0:
+        answer.append(dict(name=item["displayName"], children=list()))
+      else:
+        # TODO Proper logging
+        print "Unexpected iconLists length: %d -- %s" % (len(item["iconLists"]), item)
+    elif isinstance(item, (str, unicode)):
+      answer.append(dict(name=item, zipped_size=1, full_size=1))
+    else:
+      # TODO Proper logging
+      print "Expected str or dict but found %s: %s" % (type(item), item)
+  return dict(name=name, children=list(answer))
+
+def springboard_to_d3(flo):
+  data = json.load(flo)
+  answer = dict()
+  answer["name"] = "Apps on TODO"
+  answer["children"] = list()
+  x = 0
+  for page in data["iconLists"]:
+    x += 1
+    answer["children"].append(process_node("Screen %d" % x, page))
+  answer["children"].append(process_node("Button Bar", data["buttonBar"]))
+  return answer
+
+if __name__ == '__main__':
+  with open("springboard.json") as infile:
+    pprint.pprint(springboard_to_d3(infile))