-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (71 loc) · 3.23 KB
/
Copy pathapp.py
File metadata and controls
90 lines (71 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pymysql
from flask import Flask, flash, render_template, request, redirect, url_for, session
from flask_mysqldb import MySQL
from werkzeug.security import generate_password_hash, check_password_hash
import time
import datetime
import MySQLdb.cursors
import re
app = Flask(__name__)
app.secret_key = 'TIGER'
app.config['MYSQL_HOST'] = 'sql6.freemysqlhosting.net'
app.config['MYSQL_USER'] = 'sql6399119'
app.config['MYSQL_PASSWORD'] = 'pWBRQrYnmJ'
app.config['MYSQL_DB'] = 'sql6399119'
mysql = MySQL(app)
ts = time.time()
timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
@app.route('/')
def index():
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT * FROM customers")
data1 = cursor.fetchall()
return render_template('index.html', data=data1)
@app.route('/transaction', methods=['GET', 'POST'])
def make():
msg = 'Please enter details to be added'
if request.method == 'POST' and 'cid' in request.form and 'cname' in request.form and 'cemail' in request.form and 'cbal' in request.form:
user = request.form['cname']
id = request.form['cid']
email = request.form['cemail']
bal = request.form['cbal']
cursor = mysql.connection.cursor()
cursor.execute("SELECT name,id FROM customers WHERE id=%s", (id,))
pid = cursor.fetchall()
return render_template('make.html',value=pid,value1=user,value2=id,value3=email,value4=bal)
@app.route("/transactions", methods=['GET', 'POST'])
def transact():
if request.method == 'POST' and 'reciever' in request.form and 'amount' in request.form and 'pname' in request.form and 'pbal' in request.form:
reciever = request.form['reciever']
amount = float(request.form['amount'])
amount1 = float(request.form['amount'])
sender = request.form['pname']
scurrbal = float(request.form['pbal'])
cursor = mysql.connection.cursor()
sbal = scurrbal - amount
cursor.execute("SELECT curr_bal FROM customers WHERE name=%s", (reciever,))
rcurr_bal = cursor.fetchone()
rcurrbal = float(rcurr_bal[0])
rbal = rcurrbal + amount1
print(rcurrbal)
print(rbal)
cursor.execute("SELECT * FROM transactions WHERE sname=%s", (sender,))
tid = cursor.fetchall()
if scurrbal >= amount:
cursor.execute("UPDATE customers SET curr_bal=%s where name=%s", (rbal, reciever,))
cursor.execute("UPDATE customers SET curr_bal=%s where name=%s", (sbal, sender,))
cursor.execute("INSERT INTO transactions(sname,rname,amount) VALUES ( %s, %s,%s)",
(sender, reciever, amount,))
mysql.connection.commit()
else:
return "Insufficient Funds!"
return redirect(url_for('transhis'))
# return render_template('transact.html',value=tid)
@app.route('/history')
def transhis():
cursor = mysql.connection.cursor()
cursor.execute('SELECT * FROM transactions ORDER BY time DESC')
data1 = cursor.fetchall()
return render_template('tranhis.html', data=data1)
if __name__ == "__main__":
app.run(debug=True);