fix some linting errors
mostly variable/function names and spacing
This commit is contained in:
parent
c32117a7b5
commit
6dd4161339
60
test.py
60
test.py
|
@ -6,14 +6,14 @@ from flask import Flask, render_template
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
attributes= ["title",
|
attributes = ["title",
|
||||||
"authors",
|
"authors",
|
||||||
"isbn"]
|
"isbn"]
|
||||||
|
|
||||||
fields = {}
|
fields = {}
|
||||||
|
|
||||||
@app.route("/r")
|
@app.route("/r")
|
||||||
def updateData():
|
def update_data():
|
||||||
global data
|
global data
|
||||||
out = []
|
out = []
|
||||||
|
|
||||||
|
@ -31,40 +31,40 @@ def updateData():
|
||||||
name = field.attrib["name"]
|
name = field.attrib["name"]
|
||||||
fields[name] = field.attrib
|
fields[name] = field.attrib
|
||||||
|
|
||||||
for book in collection.iter(ns + "entry"):
|
for entry in collection.iter(ns + "entry"):
|
||||||
bookout = {}
|
bookout = {}
|
||||||
for dName in fields.keys():
|
for datum_name in fields.keys():
|
||||||
datum = book.find(ns + dName)
|
datum = entry.find(ns + datum_name)
|
||||||
if datum != None:
|
if datum != None:
|
||||||
t = int(fields[dName]["type"])
|
datum_type = int(fields[datum_name]["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 datum_type == 1 or datum_type == 2 or datum_type == 3 or datum_type == 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[dName]["flags"]) & 0x01 & 0xff) != 0:
|
if (int(fields[datum_name]["flags"]) & 0x01 & 0xff) != 0:
|
||||||
bookout[dName] = []
|
bookout[datum_name] = []
|
||||||
for sub in datum:
|
for sub in datum:
|
||||||
bookout[dName].append(sub.text)
|
bookout[datum_name].append(sub.text)
|
||||||
else:
|
else:
|
||||||
bookout[dName] = datum.text
|
bookout[datum_name] = datum.text
|
||||||
|
|
||||||
#date
|
#date
|
||||||
elif t == 12:
|
elif datum_type == 12:
|
||||||
bookout[dName] = ""
|
bookout[datum_name] = ""
|
||||||
if datum.find(ns + "year") != None:
|
if datum.find(ns + "year") != None:
|
||||||
bookout[dName] += datum.find(ns + "year").text
|
bookout[datum_name] += datum.find(ns + "year").text
|
||||||
if datum.find(ns + "month") != None:
|
if datum.find(ns + "month") != None:
|
||||||
bookout[dName] += "-" + datum.find(ns + "month").text
|
bookout[datum_name] += "-" + datum.find(ns + "month").text
|
||||||
if datum.find(ns + "day") != None:
|
if datum.find(ns + "day") != None:
|
||||||
bookout[dName] += "-" + datum.find(ns + "day").text
|
bookout[datum_name] += "-" + datum.find(ns + "day").text
|
||||||
|
|
||||||
elif t == 6: #Number
|
elif datum_type == 6: #Number
|
||||||
bookout[dName] = datum.text
|
bookout[datum_name] = datum.text
|
||||||
else:
|
else:
|
||||||
print("Did not parse:" + dName + ", type:" + str(t))
|
print("Did not parse:" + datum_name + ", type:" + str(datum_type))
|
||||||
bookout[dName] = ""
|
bookout[datum_name] = ""
|
||||||
else:
|
else:
|
||||||
bookout[dName] = ""
|
bookout[datum_name] = ""
|
||||||
out.append(bookout.copy())
|
out.append(bookout.copy())
|
||||||
data = out.copy()
|
data = out.copy()
|
||||||
return "success"
|
return "success"
|
||||||
|
@ -72,15 +72,15 @@ def updateData():
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def main():
|
def main():
|
||||||
if data == []:
|
if data == []:
|
||||||
updateData()
|
update_data()
|
||||||
return render_template("main.html", books = data, attributes = attributes)
|
return render_template("main.html", books=data, attributes=attributes)
|
||||||
|
|
||||||
@app.route("/book/<int:id>")
|
@app.route("/book/<int:id_num>")
|
||||||
def book(id):
|
def book(id_num):
|
||||||
if data == []:
|
if data == []:
|
||||||
updateData()
|
update_data()
|
||||||
book = next((item for item in data if int(item["id"]) == id), {})
|
entry = next((item for item in data if int(item["id"]) == id_num), {})
|
||||||
return render_template("book.html", book = book, fields = fields)
|
return render_template("book.html", book=entry, fields=fields)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(debug=True, host='0.0.0.0')
|
app.run(debug=True, host='0.0.0.0')
|
||||||
|
|
Loading…
Reference in New Issue