-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.py
102 lines (85 loc) · 3.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pymysql
import config
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
host_name = config.DB_CONFIG['stores_host']
port_name = config.DB_CONFIG['stores_port']
user_name = config.DB_CONFIG['stores_user']
pwd = config.DB_CONFIG['stores_passwd']
db_name = config.DB_CONFIG['stores_db']
# database 에 접근
# database 를 사용하기 위한 cursor 를 세팅합니다.
@app.route('/')
def home():
return render_template('index.html', map_key=config.API_KEY['kakao_map_api'])
@app.route('/list')
def myList():
return render_template('mylist.html', map_key=config.API_KEY['kakao_map_api'])
@app.route('/search')
def foodSearch():
return render_template('food-search.html', map_key=config.API_KEY['kakao_map_api'])
@app.route('/map', methods=['POST'])
def saving():
author_receive = request.form['author_give']
store_receive = request.form['store_give'] # 가게 명
address_receive = request.form['address_give'] # 가게 주소
tel_receive = request.form['tel_give'] # 가게 전화번호
lat_receive = request.form['lat_give'] # 위도
lng_receive = request.form['lng_give'] # 경도
db = pymysql.connect(host=host_name,
port=port_name,
user=user_name,
passwd=pwd,
db=db_name,
charset='utf8')
try:
with db.cursor() as cursor:
sql = "INSERT INTO stores(author, store, address, tel, lat, lng) VALUES (%s, %s, %s, %s, %s, %s)"
cursor.execute(sql, (author_receive, store_receive, address_receive, tel_receive, lat_receive, lng_receive))
db.commit()
except pymysql.err.IntegrityError:
return jsonify({'result': 'fail', 'msg': '중복값 체크!'})
finally:
db.close()
return jsonify({'result': 'success', 'msg': '이 요청은 POST!'})
@app.route('/map', methods=['GET'])
def listing():
db = pymysql.connect(host=host_name,
port=port_name,
user=user_name,
passwd=pwd,
db=db_name,
charset='utf8')
try:
with db.cursor(pymysql.cursors.DictCursor) as cursor:
# Create a new record
sql = "SELECT * FROM stores"
cursor.execute(sql)
rows = cursor.fetchall()
# connection is not autocommit by default. So you must commit to save
# your changes.
finally:
db.close()
return jsonify({'result': 'success', 'rows': rows})
@app.route('/delete', methods=['POST'])
def deleting():
store_give = request.args.get('store_give')
# host ='my aws host ip'
db = pymysql.connect(host=host_name,
port=port_name,
user=user_name,
passwd=pwd,
db=db_name,
charset='utf8')
try:
with db.cursor() as cursor:
sql = "DELETE FROM stores WHERE store = %s"
cursor.execute(sql, store_give)
db.commit()
# connection is not autocommit by default. So you must commit to save
# your changes.
finally:
db.close()
return jsonify({'result': 'success', 'msg': '이 요청은 POST!'})
if __name__ == '__main__':
app.run('0.0.0.0', port=5001, debug=True)