'''Flask/PyMySQL app to list the people in the WMDB. Scott D. Anderson revised Fall 2019 for Python3 revised Spring 2020 for new dbi module ''' from flask import (Flask, url_for, render_template) import cs304dbi as dbi import servertime import people app = Flask(__name__) @app.route('/') def hello_world(): tmpl = '''

Hello Everyone!

Click here for people list

Click here for list of people born in June

Click here for list of people born on Monday

''' page = tmpl.format(url1=url_for('people_list'), url2=url_for('people_born_in_month',month=6), url3=url_for('people_born_on_weekday',weekday=1) ) return page @app.route('/people/') def people_list(): conn = dbi.connect() folk = people.get_people(conn) now = servertime.now() return render_template('people-list.html', desc='WMDB People as of {}'.format(now), people=folk) month_names = ['skip', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] @app.route('/people-born-in/') def people_born_in_month(month): conn = dbi.connect() folk = people.people_born_in_month(conn,month) head = 'WMDB People born in {}'.format(month_names[month]) return render_template('people-list.html', desc=head, people=folk) day_names = ('skip', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') @app.route('/people-born-on/') def people_born_on_weekday(weekday): conn = dbi.connect() folk = people.people_born_on_weekday(conn,weekday) head = 'WMDB People born on {}'.format(day_names[weekday]) return render_template('people-list.html', desc=head, people=folk) @app.before_first_request def startup(): dbi.conf('wmdb') if __name__ == '__main__': import os uid = os.getuid() app.debug = True app.run('0.0.0.0',uid)