40 lines
897 B
Python
40 lines
897 B
Python
|
#!/usr/bin/python
|
||
|
|
||
|
import xml.etree.ElementTree as ET
|
||
|
import json
|
||
|
import fileinput
|
||
|
import sys
|
||
|
|
||
|
if len(sys.argv) == 2 and sys.argv[1] == '-h':
|
||
|
print(sys.argv[0], ': Convert Practice Timer 1 data into Praceice Timer 2 data')
|
||
|
print(sys.argv[0], ': usage: ', sys.argv[0], ' <input>')
|
||
|
print(sys.argv[0], ': output will be on stdout. Input can also be read from stdin')
|
||
|
exit(0)
|
||
|
|
||
|
xmlData = ""
|
||
|
|
||
|
for f in fileinput.input():
|
||
|
xmlData += f
|
||
|
|
||
|
root = ET.fromstring(xmlData)
|
||
|
|
||
|
headers = root[1]
|
||
|
|
||
|
jo = []
|
||
|
|
||
|
for header in headers:
|
||
|
ho = {
|
||
|
"date": int(round(int(header.get('date')) / 1000)),
|
||
|
"tasks": []
|
||
|
}
|
||
|
for task in header:
|
||
|
to = {
|
||
|
"name": task.get('name'),
|
||
|
"length": int(task.get('length')),
|
||
|
"start": int(round(int(task.get('start')) / 1000))
|
||
|
}
|
||
|
ho['tasks'].append(to)
|
||
|
jo.append(ho)
|
||
|
|
||
|
print(json.dumps(jo))
|