mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-19 12:13:43 +00:00
Add whitespace to convert_josm.py
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user