Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- print("Content-type: text/html\n")
- import cgi
- import MySQLdb
- form = cgi.FieldStorage()
- string = "i211f18_affoster"
- password = "my+sql=i211f18_affoster"
- db_con = MySQLdb.connect(host = "db.soic.indiana.edu", port = 3306, user = string, passwd = password, db = string)
- cursor = db_con.cursor()
- html = "<!doctype html>"
- html += "<html>"
- html += """<head><meta charset = "utf-8">"""
- html += "<title>Robot Delivery System Confirmation</title>"
- html += "<head>"
- html += "<body>"
- html += "<h1>Robot Delivery System Confirmation</h1>"
- html += "<br>"
- html += "<p>You have selected to have a {0} delivered by {1}.</p>"
- html += "<p>Your total comes out to ${2}</p>"
- costs = {"drone":10, "car":20, "robot":1000, "nothing":0, "item wrong":0, "type wrong": 0}
- cost = form.getfirst("cost", 0)
- item = form.getfirst("item", "item wrong")
- type = form.getfirst("method", "type wrong")
- html = html.format(item, type, str(int(cost) + costs[type]))
- html += "<h2>Delivery Records</h2><br>"
- try:
- sql = "insert into deliveries(item, cost, method, shipping) values ('" + item + "', " + str(cost) + ", '" + type + "', " + str(costs[type]) + ");"
- print(sql)
- cursor.execute(sql)
- db_con.commit()
- except:
- print("Something went wrong")
- else:
- sql = "select d.item, d.cost, d.method, d.shipping from deliveries as d;"
- cursor.execute(sql)
- results = cursor.fetchall()
- html += """<table border = 1><tr><th>Item</th><th>Cost</th><th>Method</th><th>Shipping</th></tr>"""
- for row in results:
- html += """<tr>"""
- for elem in row:
- html += "<td>" + str(elem) + "</td>"
- html += """</tr>"""
- html += "</table>"
- html += """</body>
- </html>"""
- print(html)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement