-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmpApp.py
85 lines (63 loc) · 2.25 KB
/
EmpApp.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from flask import Flask, render_template, request
from pymysql import connections
import os
import boto3
from config import *
app = Flask(__name__)
bucket = custombucket
region = customregion
db_conn = connections.Connection(
host=customhost,
port=3306,
user=customuser,
password=custompass,
db=customdb
)
output = {}
table = 'employee'
@app.route("/", methods=['GET', 'POST'])
def home():
return render_template('AddEmp.html')
@app.route("/about", methods=['POST'])
def about():
return render_template('www.saradhiatluri.ga')
@app.route("/addemp", methods=['POST'])
def AddEmp():
emp_id = request.form['emp_id']
first_name = request.form['first_name']
last_name = request.form['last_name']
pri_skill = request.form['pri_skill']
location = request.form['location']
emp_image_file = request.files['emp_image_file']
insert_sql = "INSERT INTO employee VALUES (%s, %s, %s, %s, %s)"
cursor = db_conn.cursor()
#if emp_image_file.filename == "":
#return "Please select a file"
try:
cursor.execute(insert_sql, (emp_id, first_name, last_name, pri_skill, location))
db_conn.commit()
emp_name = "" + first_name + " " + last_name
# Uplaod image file in S3 #
emp_image_file_name_in_s3 = "emp-id-" + str(emp_id) + "_image_file"
s3 = boto3.resource('s3')
try:
print("Data inserted in MySQL RDS... uploading image to S3...")
s3.Bucket(custombucket).put_object(Key=emp_image_file_name_in_s3, Body=emp_image_file)
bucket_location = boto3.client('s3').get_bucket_location(Bucket=custombucket)
s3_location = (bucket_location['LocationConstraint'])
if s3_location is None:
s3_location = ''
else:
s3_location = '-' + s3_location
object_url = "https://s3{0}.amazonaws.com/{1}/{2}".format(
s3_location,
custombucket,
emp_image_file_name_in_s3)
except Exception as e:
return str(e)
finally:
cursor.close()
print("all modification done...")
return render_template('AddEmpOutput.html', name=emp_name)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80, debug=True)