add datum variable to remove redundant code
renames datum to dName also fix date parsing (was using book, not datum)
This commit is contained in:
parent
af09386e83
commit
c32117a7b5
39
test.py
39
test.py
|
@ -33,37 +33,38 @@ def updateData():
|
||||||
|
|
||||||
for book in collection.iter(ns + "entry"):
|
for book in collection.iter(ns + "entry"):
|
||||||
bookout = {}
|
bookout = {}
|
||||||
for datum in fields.keys():
|
for dName in fields.keys():
|
||||||
if book.find(ns + datum) != None:
|
datum = book.find(ns + dName)
|
||||||
t = int(fields[datum]["type"])
|
if datum != None:
|
||||||
|
t = int(fields[dName]["type"])
|
||||||
#simple text, paragraph, multiple choice, image
|
#simple text, paragraph, multiple choice, image
|
||||||
if t == 1 or t == 2 or t == 3 or t == 10:
|
if t == 1 or t == 2 or t == 3 or t == 10:
|
||||||
#check if multiple entries are allowed
|
#check if multiple entries are allowed
|
||||||
#if so, put entries in a list
|
#if so, put entries in a list
|
||||||
if (int(fields[datum]["flags"]) & 0x01 & 0xff) != 0:
|
if (int(fields[dName]["flags"]) & 0x01 & 0xff) != 0:
|
||||||
bookout[datum] = []
|
bookout[dName] = []
|
||||||
for sub in book.find(ns + datum):
|
for sub in datum:
|
||||||
bookout[datum].append(sub.text)
|
bookout[dName].append(sub.text)
|
||||||
else:
|
else:
|
||||||
bookout[datum] = book.find(ns + datum).text
|
bookout[dName] = datum.text
|
||||||
|
|
||||||
#date
|
#date
|
||||||
elif t == 12:
|
elif t == 12:
|
||||||
bookout[datum] = ""
|
bookout[dName] = ""
|
||||||
if book.find(ns + "year") != None:
|
if datum.find(ns + "year") != None:
|
||||||
bookout[datum] += book.find(ns + "year").text
|
bookout[dName] += datum.find(ns + "year").text
|
||||||
if book.find(ns + "month") != None:
|
if datum.find(ns + "month") != None:
|
||||||
bookout[datum] += "-" + book.find(ns + "month").text
|
bookout[dName] += "-" + datum.find(ns + "month").text
|
||||||
if book.find(ns + "day") != None:
|
if datum.find(ns + "day") != None:
|
||||||
bookout[datum] += "-" + book.find(ns + "day").text
|
bookout[dName] += "-" + datum.find(ns + "day").text
|
||||||
|
|
||||||
elif t == 6: #Number
|
elif t == 6: #Number
|
||||||
bookout[datum] = book.find(ns + datum).text
|
bookout[dName] = datum.text
|
||||||
else:
|
else:
|
||||||
print(str(t) + ": " + datum)
|
print("Did not parse:" + dName + ", type:" + str(t))
|
||||||
bookout[datum] = ""
|
bookout[dName] = ""
|
||||||
else:
|
else:
|
||||||
bookout[datum] = ""
|
bookout[dName] = ""
|
||||||
out.append(bookout.copy())
|
out.append(bookout.copy())
|
||||||
data = out.copy()
|
data = out.copy()
|
||||||
return "success"
|
return "success"
|
||||||
|
|
Loading…
Reference in New Issue