2018-06-21 15:50:01 -04:00
|
|
|
#!/usr/bin/env python3
|
2018-08-16 10:59:31 -04:00
|
|
|
import http
|
2020-03-30 14:01:39 -04:00
|
|
|
import re
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2018-08-13 16:27:15 -04:00
|
|
|
from flask import Flask, render_template, request
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
from common import doors, membershipworks
|
|
|
|
|
2018-06-21 15:50:01 -04:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def parse_list(member, regex):
|
|
|
|
data_list = []
|
|
|
|
for key, value in member.items():
|
|
|
|
match = re.match(regex, key)
|
2020-03-30 14:01:39 -04:00
|
|
|
if match is not None and value != "":
|
2018-06-21 15:50:01 -04:00
|
|
|
data_list.append(match.group(1))
|
|
|
|
|
|
|
|
return ", ".join(data_list)
|
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
|
2018-06-21 15:50:01 -04:00
|
|
|
def parse_members(members):
|
|
|
|
data = []
|
|
|
|
for member in members:
|
|
|
|
props = {
|
2020-03-30 14:01:39 -04:00
|
|
|
"Name": member["Account Name"],
|
|
|
|
"Renewal Date": member["Renewal Date"],
|
|
|
|
"Card Number": member["Access Card Facility Code"]
|
|
|
|
+ "-"
|
|
|
|
+ member["Access Card Number"],
|
|
|
|
"Account on Hold": "Yes" if member["Account on Hold"] != "" else "No",
|
|
|
|
}
|
|
|
|
|
|
|
|
props["Certifications"] = parse_list(member, "Certified: (.*)")
|
|
|
|
props["Door Access"] = parse_list(member, "Access (.*)\?")
|
|
|
|
props["Memebership Level"] = parse_list(member, "CMS (.*)")
|
2018-06-21 15:50:01 -04:00
|
|
|
|
|
|
|
data.append(props)
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
|
2018-06-21 15:50:01 -04:00
|
|
|
@app.route("/")
|
|
|
|
def main():
|
|
|
|
# maybe not now: membership agreement signed
|
2018-08-13 16:27:15 -04:00
|
|
|
# TODO: renewal date check
|
2020-03-30 14:01:39 -04:00
|
|
|
term = request.args.get("term", "")
|
2018-08-13 16:27:15 -04:00
|
|
|
|
|
|
|
if len(term) < 3:
|
2020-03-30 14:01:39 -04:00
|
|
|
return render_template(
|
|
|
|
"members.html", error="Enter at least 3 characters to search"
|
|
|
|
)
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2020-02-06 17:48:09 -05:00
|
|
|
data = membershipworks.get_members(
|
2020-03-30 14:01:39 -04:00
|
|
|
["members", "staff"], "lvl,xws,xms,xsc,xas,xfd,xac,phn,eml,lbl,xcf,nam,end"
|
|
|
|
)
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2018-08-13 16:27:15 -04:00
|
|
|
members = parse_members(data)
|
2020-03-30 14:01:39 -04:00
|
|
|
members = [member for member in members if term.lower() in member["Name"].lower()]
|
|
|
|
headers = [
|
|
|
|
"Name",
|
|
|
|
"Certifications",
|
|
|
|
"Door Access",
|
|
|
|
"Memebership Level",
|
|
|
|
"Card Number",
|
|
|
|
"Renewal Date",
|
|
|
|
"Account on Hold",
|
|
|
|
]
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2018-08-13 16:27:15 -04:00
|
|
|
if len(members) > 4:
|
|
|
|
return render_template(
|
2020-03-30 14:01:39 -04:00
|
|
|
"members.html", error="Too many results, please be more specific."
|
|
|
|
)
|
2018-08-13 16:27:15 -04:00
|
|
|
|
|
|
|
return render_template("members.html", headers=headers, members=members)
|
2018-06-21 15:50:01 -04:00
|
|
|
|
2020-03-30 14:01:39 -04:00
|
|
|
|
|
|
|
@app.route("/frontDoor/<lock>", methods=["POST"])
|
2018-08-16 10:59:31 -04:00
|
|
|
def unlockLockDoor(lock):
|
2020-03-30 14:01:39 -04:00
|
|
|
doors["Front Door"].lockOrUnlockDoor(lock != "unlock")
|
|
|
|
return ("", http.HTTPStatus.NO_CONTENT)
|
|
|
|
|
2018-08-16 10:59:31 -04:00
|
|
|
|
2018-06-21 15:50:01 -04:00
|
|
|
if __name__ == "__main__":
|
2020-03-30 14:01:39 -04:00
|
|
|
app.run(debug=True, host="0.0.0.0")
|