final Exam Format
Once Again, for your final exam you will have 2 parts:
- (REMOVED) part 1 50%: paper exam in a format similar to midterm exam format; closed books, closed notes; 1 hr hard
- part 2 100%: you will have to write a program, the assignment will be similar to the assignment below. 2hrs hard
- Your program must be all written in 1 file, I should be able to run 1 file and it should work, use your first and last name to name your file
- The program must be submitted via a form that will be available for your exam.
- Everyone will receive a different assignment, if I notice a wrong assignment submitted, the grade for the 2nd part will be 0
Sample part2 assignment
final_exam.sqlite |
Download the database (above)
Use following query to retrieve data: SELECT CountryName, TotalArea FROM COUNTRIES
Sample query for data storage you will have to do: INSERT INTO COUNTRIES(CountryName, TotalArea) Values('test2', '123')
Using one of: WSGI, HTTPServer, Flask (I used WSGI) servers, write a program that will display the data received from the query above on a web page (see sample below)
Allow user add new country and total area, use exception handling mechanism to handle errors during the INSERT, I will test this by modifying the name tag of your input field (see sample HTML below)
Grade breakdown
Connection to database and database operations work correctly - 25%
Web Page is displayed as expected - 25%
Web page to server operation works correctly - 25%
Exceptions/Errors as described below are handled correctly - 15%
Code is clean, well commented and does not contain unneeded copy-pasted chunks (Python code only, I don't care for HTML) - 10%
Initial Web Page:
Use following query to retrieve data: SELECT CountryName, TotalArea FROM COUNTRIES
Sample query for data storage you will have to do: INSERT INTO COUNTRIES(CountryName, TotalArea) Values('test2', '123')
Using one of: WSGI, HTTPServer, Flask (I used WSGI) servers, write a program that will display the data received from the query above on a web page (see sample below)
Allow user add new country and total area, use exception handling mechanism to handle errors during the INSERT, I will test this by modifying the name tag of your input field (see sample HTML below)
Grade breakdown
Connection to database and database operations work correctly - 25%
Web Page is displayed as expected - 25%
Web page to server operation works correctly - 25%
Exceptions/Errors as described below are handled correctly - 15%
Code is clean, well commented and does not contain unneeded copy-pasted chunks (Python code only, I don't care for HTML) - 10%
Initial Web Page:
COUNTRIES DATA
Country | Total Area |
Russia | 17098242 |
Canada | 9984670 |
China | 9572900 |
United States | 9526468 |
Brazil | 8515767 |
Australia | 7692024 |
India | 3166414 |
Argentina | 2780400 |
Kazakhstan | 2724900 |
Submitted Web page - France added
COUNTRIES DATA
Country | Total Area |
Russia | 17098242 |
Canada | 9984670 |
China | 9572900 |
United States | 9526468 |
Brazil | 8515767 |
Australia | 7692024 |
India | 3166414 |
Argentina | 2780400 |
Kazakhstan | 2724900 |
France | 1111111111111 |
Insert exception handled
COUNTRIES DATA
an error has occurredCountry | Total Area |
Russia | 17098242 |
Canada | 9984670 |
China | 9572900 |
United States | 9526468 |
Brazil | 8515767 |
Australia | 7692024 |
India | 3166414 |
Argentina | 2780400 |
Kazakhstan | 2724900 |
France | 1111111111111 |
For extra 10% of the exam grade:
(5%) create a data visualization for your project using either TKINTER or HTML/public web services (ex. Google Charts). Here is a simplest example using TKINTER that would satisfy the extra credit
(5%) test program and handle SQL injection (submit a proof of SQL injection handled in the program - comment it)
(5%) create a data visualization for your project using either TKINTER or HTML/public web services (ex. Google Charts). Here is a simplest example using TKINTER that would satisfy the extra credit
(5%) test program and handle SQL injection (submit a proof of SQL injection handled in the program - comment it)
import sqlite3 from wsgiref.simple_server import make_server import tkinter def get_form_vals(post_str): form_vals = {item.split("=")[0]: item.split("=")[1] for item in post_str.decode().split("&")} return form_vals def countries_app(environ, start_response): conn = sqlite3.connect("Final_Exam.sqlite") cursor = conn.cursor() message = "<h1>COUNTRIES DATA</h1>" if(environ['REQUEST_METHOD'] == 'POST'): request_body_size = int(environ['CONTENT_LENGTH']) request_body = environ['wsgi.input'].read(request_body_size) form_vals = get_form_vals(request_body) try: sql="INSERT INTO COUNTRIES(Country, TotalArea) Values('"+form_vals['country']+"', '"+form_vals['area']+"')" cursor.execute(sql) conn.commit() except: message+="<font color=red>an error has occurred</font>" status = '200 OK' headers = [('Content-type', 'html; charset=utf-8')] start_response(status, headers) result = cursor.execute("select Country, TotalArea from COUNTRIES") message+="<table>" message+="<tr><td>Country</td><td>Total Area</td></tr>" for row in result: message+="<tr>" for column in row: message+="<td>"+str(column)+"</td>" message+="</tr>" message+="</table><br/>" message+="<form method='POST'>Add Record:<br/><br/>" message+="Country:<input type='text' name='country'><br/><br/>" message+="Total Area:<input type='number' name='area'><br/><br/>" message+="<input type='Submit'>" return[bytes(message,'utf-8')] conn.close() ''' base = tkinter.Tk() base.title("Countries Data") canvas = tkinter.Canvas(base, bg="white", height=1000, width=1000) conn = sqlite3.connect("Final_Exam.sqlite") cursor = conn.cursor() result = cursor.execute("select Country, TotalArea from COUNTRIES") l = 0 for row in result: l+=50 canvas.create_text(100,l-10, text=row[0]) canvas.create_line(200,l , int(row[1])/50000+200, l, fill="black") canvas.pack() base.mainloop() ''' httpd = make_server('', 8000, countries_app) print("Serving on port 8000...") httpd.serve_forever()