From 6048990ea9a2459c7a58d75e1a93e0ce6a4a628c Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 21 Jun 2018 15:50:01 -0400 Subject: [PATCH] membershipViewer: Add basic front desk web page thingy --- membershipViewer.py | 56 ++++++++++++++++++++++++++++++++++++++++++ templates/members.html | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 membershipViewer.py create mode 100644 templates/members.html diff --git a/membershipViewer.py b/membershipViewer.py new file mode 100644 index 0000000..4459900 --- /dev/null +++ b/membershipViewer.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +import re + +from flask import Flask, render_template + +app = Flask(__name__) + +from common import * + +def parse_list(member, regex): + data_list = [] + for key, value in member.items(): + match = re.match(regex, key) + if match is not None and value != '': + data_list.append(match.group(1)) + + return ", ".join(data_list) + +def parse_members(members): + data = [] + for member in members: + props = { + '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" } + + certifications = [] + access = [] + levels = [] + + props['Certifications'] = parse_list(member, 'Certified: (.*)') + props['Door Access'] = parse_list(member, 'Access (.*)\?') + props['Memebership Level'] = parse_list(member, 'CMS (.*)') + + data.append(props) + + return data + +@app.route("/") +def main(): + # maybe not now: membership agreement signed + # TODO: renewal date + + members = getMembershipworksData( + "lvl,xws,xms,xsc,xas,xfd,xac,phn,eml,lbl,xcf,nam,end") + + data = parse_members(members) + headers = ['Name', 'Certifications', 'Door Access', 'Memebership Level', + 'Card Number', 'Renewal Date', 'Account on Hold'] + + return render_template("members.html", headers=headers, members=data) + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0') diff --git a/templates/members.html b/templates/members.html new file mode 100644 index 0000000..a3e6bf7 --- /dev/null +++ b/templates/members.html @@ -0,0 +1,44 @@ + + + CMS Members + + + +

Members

+ + + {% for header in headers %} + + {% endfor %} + + {% for member in members %} + + {% for header in headers %} + + {% endfor %} + + {% endfor %} + +
{{ header }}
{{ member[header] }}
+ +