-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmf2tojf2.py
36 lines (30 loc) · 842 Bytes
/
mf2tojf2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# mf2 to jf2 converter
# licence cc0
# 2015 Kevin Marks
import logging
def flattenProperties(items):
if len(items) <1:
return {}
item = items[0]
if type(item) is dict:
if item.has_key("type"):
props ={"type":item.get("type",["-"])[0].split("-")[1:][0]}
properties = item.get("properties",{})
for prop in properties:
props[prop] = flattenProperties(properties[prop])
return props
elif item.has_key("value"):
return item["value"]
else:
return ''
else:
return item
def mf2tojf2(mf2):
"""I'm going to have to recurse here"""
jf2={}
items = mf2.get("items",[])
jf2=flattenProperties(items)
#print mf2, jf2
return jf2