Add whitespace to convert_josm.py

This commit is contained in:
Ansis Brammanis
2013-02-01 12:21:45 -05:00
parent cb6ae40ef0
commit ecbfbb9ff2

View File

@@ -1,55 +1,70 @@
from xml.dom.minidom import parse
import os, re, json
import json
import os
import re
dirr = os.path.dirname(__file__)
def relative(x):
return os.path.join(dirr, x)
prefs = json.load(open(relative('prefs.json')))
dom1 = parse(relative('./josm.xml'))
items = dom1.getElementsByTagName('item')
jsonOutput = []
def isemail(x):
return re.search('email', x, flags=re.IGNORECASE)
def iswebsite(x):
return re.search('web', x, flags=re.IGNORECASE)
def istel(x):
return re.search('phone|tel|fax', x, flags=re.IGNORECASE)
def isfav(x):
return x in prefs
for item in items:
for item in dom1.getElementsByTagName('item'):
tags = []
for elem in item.getElementsByTagName('key'):
tags.append({
'key': elem.getAttribute('key'),
'value': elem.getAttribute('value')
})
jitem = {
"name": item.getAttribute('name'),
"type": item.getAttribute('type').split(','),
"tags": tags,
"main": []
}
if isfav(jitem['name']):
jitem['favorite'] = True
for n in item.getElementsByTagName('text'):
txt = n.getAttribute('text')
type = 'text'
if isemail(txt):
type = 'email'
if iswebsite(txt):
elif iswebsite(txt):
type = 'url'
if istel(txt):
elif istel(txt):
type = 'tel'
jitem['main'].append({
'type': type,
'key': n.getAttribute('key'),
'text': n.getAttribute('text')
})
for n in item.getElementsByTagName('combo'):
jitem['main'].append({
'type': 'select',
@@ -57,6 +72,7 @@ for item in items:
'text': n.getAttribute('text'),
'values': n.getAttribute('values').split(',')
})
for n in item.getElementsByTagName('check'):
jitem['main'].append({
'type': 'check',
@@ -64,6 +80,7 @@ for item in items:
'text': n.getAttribute('text'),
'default': (n.getAttribute('check') == 'true')
})
jsonOutput.append(jitem)
json.dump(jsonOutput, open(relative('presets_josm.json'), 'w'), indent=4)