forked from williamyen0623/AI_FinalProject_Group9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_operation.py
145 lines (140 loc) · 5.68 KB
/
sql_operation.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sqlite3
import random
from line_chatbot_api import *
current={"count":0, "now":0}
def get_reply_from_audio(user_choices):
food_db_conn = sqlite3.connect('food_db')
food_db_cur = food_db_conn.cursor()
cursor = food_db_cur.execute(
'''
SELECT NAME,FEATURE,OPENTIME,OPENDAY,ADDRESS,PHONENUM,RATING,RATINGTOTAL,LAT,LNG FROM FOODLIST
WHERE FEATURE = '{}' AND RATING >= {} AND OPENTIME LIKE '%{}%' AND OPENDAY LIKE '%{}%';
'''.format(user_choices['feature'], user_choices['rating'], user_choices['meal'], user_choices['day'])
)
count = 0
user_response_resturant = []
for row in cursor:
reply_messsage = ''
print("NAME = ", row[0])
print("FEATURE = ", row[1])
print("OPENTIME = ", row[2])
print("OPENDAY = ", row[3])
print("ADDRESS = ", row[4])
print("PHONENUM = ", row[5])
print("RATING = ", row[6])
print("RATINGTOTAL = ", row[7])
print("LAT = ", row[8])
print("LNG = ", row[9], "\n")
count += 1
current['count'] += 1
reply_messsage += '店名:{}\n地址:{}\n電話:{}\n評價:{}\n評論數:{}'.format(row[0], row[4], row[5], row[6], row[7])
user_response_resturant.append(TextSendMessage(text=reply_messsage))
user_response_resturant.append(LocationSendMessage(title=row[0],address=row[4],latitude=row[8],longitude=row[9]))
if(count == 2): break
if(count == 0):
user_response_resturant.append(TextSendMessage(text="很抱歉,沒有符合您需求的餐廳"))
else:
user_response_resturant.append(TemplateSendMessage(
alt_text='給programmer看的, 不會顯示',
template=ConfirmTemplate(
text='請問要查詢更多餐廳嗎?',
actions=[
MessageAction(
label='結束查詢',
text='結束查詢'
),
MessageAction(
label='顯示更多',
text='顯示更多'
)
]
)))
food_db_conn.commit()
food_db_conn.close()
return user_response_resturant
def get_more_rest(user_choices):
food_db_conn = sqlite3.connect('food_db')
food_db_cur = food_db_conn.cursor()
cursor = food_db_cur.execute(
'''
SELECT NAME,FEATURE,OPENTIME,OPENDAY,ADDRESS,PHONENUM,RATING,RATINGTOTAL,LAT,LNG FROM FOODLIST
WHERE FEATURE = '{}' AND RATING >= {} AND OPENTIME LIKE '%{}%' AND OPENDAY LIKE '%{}%';
'''.format(user_choices['feature'], user_choices['rating'], user_choices['meal'], user_choices['day'])
)
count = 0
user_response_resturant = []
current['now'] = 0
for row in cursor:
current['now'] += 1
if(current['count'] >= current['now']):
continue
reply_messsage = ''
print("NAME = ", row[0])
print("FEATURE = ", row[1])
print("OPENTIME = ", row[2])
print("OPENDAY = ", row[3])
print("ADDRESS = ", row[4])
print("PHONENUM = ", row[5])
print("RATING = ", row[6])
print("RATINGTOTAL = ", row[7])
print("LAT = ", row[8])
print("LNG = ", row[9], "\n")
count += 1
current['count'] += 1
reply_messsage += '店名:{}\n地址:{}\n電話:{}\n評價:{}\n評論數:{}'.format(row[0], row[4], row[5], row[6], row[7])
user_response_resturant.append(TextSendMessage(text=reply_messsage))
user_response_resturant.append(LocationSendMessage(title=row[0],address=row[4],latitude=row[8],longitude=row[9]))
if(count == 2): break
if(count == 0):
user_response_resturant.append(TextSendMessage(text="很抱歉,沒有更多符合您需求的餐廳"))
else:
user_response_resturant.append(TemplateSendMessage(
alt_text='給programmer看的, 不會顯示',
template=ConfirmTemplate(
text='請問要查詢更多餐廳嗎?',
actions=[
MessageAction(
label='結束查詢',
text='結束查詢'
),
MessageAction(
label='顯示更多',
text='顯示更多'
)
]
)))
food_db_conn.commit()
food_db_conn.close()
return user_response_resturant
def set_current_count(_int_set):
current['count'] = _int_set
def get_random_rest():
random_num = random.randint(0,671)
print(random_num)
food_db_conn = sqlite3.connect('food_db')
food_db_cur = food_db_conn.cursor()
cursor = food_db_cur.execute(
'''
SELECT NAME,FEATURE,OPENTIME,OPENDAY,ADDRESS,PHONENUM,RATING,RATINGTOTAL,LAT,LNG FROM FOODLIST
WHERE NUM = {};
'''.format(random_num)
)
user_response_resturant = []
for row in cursor:
reply_messsage = ''
print("NAME = ", row[0])
print("FEATURE = ", row[1])
print("OPENTIME = ", row[2])
print("OPENDAY = ", row[3])
print("ADDRESS = ", row[4])
print("PHONENUM = ", row[5])
print("RATING = ", row[6])
print("RATINGTOTAL = ", row[7])
print("LAT = ", row[8])
print("LNG = ", row[9], "\n")
reply_messsage += '店名:{}\n地址:{}\n電話:{}\n評價:{}\n評論數:{}'.format(row[0], row[4], row[5], row[6], row[7])
user_response_resturant.append(TextSendMessage(text=reply_messsage))
user_response_resturant.append(LocationSendMessage(title=row[0],address=row[4],latitude=row[8],longitude=row[9]))
food_db_conn.commit()
food_db_conn.close()
return user_response_resturant