generated from fossterer/NuTrack
-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
67 lines (45 loc) · 1.77 KB
/
app.py
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
from flask import Flask, render_template, request, jsonify, url_for
from flask_mysqldb import MySQL
from flask_cors import CORS
app = Flask(__name__)
cors = CORS(app)
app.config['MYSQL_USER'] = 'sql3354572'
app.config['MYSQL_PASSWORD'] = 'mRAU99xW7h'
app.config['MYSQL_HOST'] = 'sql3.freemysqlhosting.net'
app.config['MYSQL_DB'] = 'sql3354572'
mysql = MySQL(app)
@app.route('/',methods=['GET','POST'])
def index():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO SampleTable (name,email) VALUES(%s,%s)",(name,email))
mysql.connection.commit()
cur.close()
return 'Done!'
return render_template('index.html')
@app.route('/data', methods=['GET','POST'])
def get_data():
if request.method == 'POST':
data = request.get_json(force=True)
#return jsonify(data)
TICKER = data.get("TICKER")
NAME = data.get("NAME")
SECURITY_TYPE = data.get("SECURITY_TYPE")
QUANTITY = data.get("QUANTITY")
PURCHASE_PRICE = data.get("PURCHASE_PRICE")
PURCHASE_DATE = data.get("PURCHASE_DATE")
print(TICKER)
print(NAME)
print(SECURITY_TYPE)
print(QUANTITY)
print(PURCHASE_PRICE)
print(PURCHASE_DATE)
cur = mysql.connection.cursor()
cur.execute("INSERT INTO DataEntryTable (TICKER,NAME,SECURITY_TYPE,QUANTITY,PURCHASE_PRICE,PURCHASE_DATE) VALUES(%s,%s,%s,%s,%s,%s)",(TICKER,NAME,SECURITY_TYPE,QUANTITY,PURCHASE_PRICE,PURCHASE_DATE))
mysql.connection.commit()
cur.close()
return "Done!"
if __name__ == "main":
app.run(debug=True)