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"):
|
||||
bookout = {}
|
||||
for datum in fields.keys():
|
||||
if book.find(ns + datum) != None:
|
||||
t = int(fields[datum]["type"])
|
||||
for dName in fields.keys():
|
||||
datum = book.find(ns + dName)
|
||||
if datum != None:
|
||||
t = int(fields[dName]["type"])
|
||||
#simple text, paragraph, multiple choice, image
|
||||
if t == 1 or t == 2 or t == 3 or t == 10:
|
||||
#check if multiple entries are allowed
|
||||
#if so, put entries in a list
|
||||
if (int(fields[datum]["flags"]) & 0x01 & 0xff) != 0:
|
||||
bookout[datum] = []
|
||||
for sub in book.find(ns + datum):
|
||||
bookout[datum].append(sub.text)
|
||||
if (int(fields[dName]["flags"]) & 0x01 & 0xff) != 0:
|
||||
bookout[dName] = []
|
||||
for sub in datum:
|
||||
bookout[dName].append(sub.text)
|
||||
else:
|
||||
bookout[datum] = book.find(ns + datum).text
|
||||
bookout[dName] = datum.text
|
||||
|
||||
#date
|
||||
elif t == 12:
|
||||
bookout[datum] = ""
|
||||
if book.find(ns + "year") != None:
|
||||
bookout[datum] += book.find(ns + "year").text
|
||||
if book.find(ns + "month") != None:
|
||||
bookout[datum] += "-" + book.find(ns + "month").text
|
||||
if book.find(ns + "day") != None:
|
||||
bookout[datum] += "-" + book.find(ns + "day").text
|
||||
bookout[dName] = ""
|
||||
if datum.find(ns + "year") != None:
|
||||
bookout[dName] += datum.find(ns + "year").text
|
||||
if datum.find(ns + "month") != None:
|
||||
bookout[dName] += "-" + datum.find(ns + "month").text
|
||||
if datum.find(ns + "day") != None:
|
||||
bookout[dName] += "-" + datum.find(ns + "day").text
|
||||
|
||||
elif t == 6: #Number
|
||||
bookout[datum] = book.find(ns + datum).text
|
||||
bookout[dName] = datum.text
|
||||
else:
|
||||
print(str(t) + ": " + datum)
|
||||
bookout[datum] = ""
|
||||
print("Did not parse:" + dName + ", type:" + str(t))
|
||||
bookout[dName] = ""
|
||||
else:
|
||||
bookout[datum] = ""
|
||||
bookout[dName] = ""
|
||||
out.append(bookout.copy())
|
||||
data = out.copy()
|
||||
return "success"
|
||||
|
Loading…
Reference in New Issue
Block a user