-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.py
268 lines (224 loc) Β· 13.6 KB
/
location.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
from telegram.ext import *
from telegram.ext.dispatcher import run_async
from telegram import *
import Responses as R
import restaurantSelection as restaurant
import DatabaseConnector as db
import choice as Choice
import contact as Contact
from datetime import datetime
import basket as Basket
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
print("Opening Selenium")
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com/maps")
count=[0]
food_holder=[]
food_price=[0]
checkers=[]
id=[]
deliveryFee=[0]
totalPrice=[0]
def location(update,context):
telegramUserName = update['message']['chat']['first_name']
mycursor = db.mydb.cursor()
sql =f"Select language FROM clients where userName='{telegramUserName}'"
mycursor.execute(sql)
checker = mycursor.fetchall()
for x in checker:
if x[0] == "English":
print("TRUEEEEEEEEEEEEEEEE")
if len(checkers) == 0:
checkers.append("Added to database")
location_keyboard = KeyboardButton(text="Share my location", request_location=True)
custom_keyboard = [[ location_keyboard]]
reply_markup = ReplyKeyboardMarkup(custom_keyboard,resize_keyboard=True,one_time_keyboard=True)
update.message.reply_text("Please turn on your device location and press the share my location button below.",reply_markup=reply_markup)
else:
print("ANOTHER")
message = update.message
current_pos = (message.location.latitude, message.location.longitude)
telegramUserName = update['message']['chat']['first_name']
mycursor = db.mydb.cursor()
mycursor.execute(f"SELECT id FROM clients WHERE userName='{telegramUserName}'")
result = mycursor.fetchall()
for x in result:
id.append(x[0])
username=telegramUserName.lower()+" basket"
mycursor = db.mydb.cursor()
sql =f"SELECT COUNT(food) FROM `{username}`"
mycursor.execute(sql)
myResult=mycursor.fetchall()
for x in myResult:
count[0]=x[0]
if count[0] > 0:
mycursor = db.mydb.cursor()
sql =f"Select * FROM `{username}`"
mycursor.execute(sql)
myResult=mycursor.fetchall()
keyboard =[]
for x in myResult:
food_price[0] = food_price[0] + int(x[3])
food_holder.append(x[1])
food_holder.append(x[2])
direction = driver.find_element_by_id("xoLGzf-T3iPGc")
direction.send_keys(Keys.RETURN)
try:
your_location = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH,"//div[@id='sb_ifc51']/input[1]"))
)
driver.find_element_by_xpath("//div[@id='sb_ifc51']/input[1]").clear()
your_location.send_keys(f"{current_pos[0]},{current_pos[1]}")
your_Destination = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH,"//div[@id='sb_ifc52']/input[1]"))
)
your_Destination.send_keys(f"{Basket.resturant_name[0].title()}")
your_Destination.send_keys(Keys.RETURN)
detail = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.ID,"section-directions-trip-details-msg-0"))
)
driver.find_element_by_id("section-directions-trip-details-msg-0").click()
km = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, "html/body/div[3]/div[9]/div[8]/div/div/div/div/div[3]/div/h1/span/span[2]/span"))
)
dis = driver.find_element_by_xpath("html/body/div[3]/div[9]/div[8]/div/div/div/div/div[3]/div/h1/span/span[2]/span").text
print(f"Diatance: {dis}")
distance = dis.replace('km','')
distance = distance.strip()
except:
print("Exception Error")
mycursor = db.mydb.cursor()
mycursor.execute(f"SELECT Distance,Price FROM deliverfee")
result = mycursor.fetchall()
for x in result:
distanceInString = x[0]
if len(distanceInString) == 3:
if float(distance) >= int(distanceInString[0]) and float(distance) < int(distanceInString[2]):
deliveryFee[0] = x[1]
break
elif len(distanceInString) == 4:
if float(distance) >= int(distanceInString[0]) and float(distance) < (int(f"{distanceInString[2]}{distanceInString[3]}")):
deliveryFee[0] = x[1]
break
elif len(distanceInString) == 5:
if float(distance) >= int(distanceInString[0]) and float(distance) < (int(f"{distanceInString[3]}{distanceInString[4]}")):
deliveryFee[0] = x[1]
break
totalPrice[0] = int(deliveryFee[0]) + food_price[0]
newline="\n"
reply_markup = InlineKeyboardMarkup(keyboard)
print(food_holder)
update.message.reply_text(f"Order\n\nπ€ ID: {id[0]}\n\nResturant: {Basket.resturant_name[0].title()}\n\nFoods:\n\n{newline.join(str(x) for x in food_holder)}\n\nTotal Food Price: {food_price[0]} Birr\nπ Delivery Fee: {int(deliveryFee[0])} Birr\nπ΅ Total Price: {totalPrice[0]} Birr",reply_markup=reply_markup)
id.pop()
totalPrice[0] = 0
food_price[0] = 0
# deliveryFee[0] = 0
keyboard = [['π Order it', 'π Maybe later'],['Restart the bot']]
message = "If your sure you want to order the food please click π Order it button if your not sure please click π Maybe later button"
reply_markup = ReplyKeyboardMarkup(keyboard,one_time_keyboard=True,resize_keyboard=True)
update.message.reply_text(message, reply_markup=reply_markup)
driver.back()
driver.back()
checkers.pop()
else:
if len(checkers) == 0:
checkers.append("Added to database")
location_keyboard = KeyboardButton(text="α α«α£α’αα ααα©", request_location=True)
custom_keyboard = [[ location_keyboard]]
reply_markup = ReplyKeyboardMarkup(custom_keyboard,resize_keyboard=True,one_time_keyboard=True)
update.message.reply_text("α₯α£ααα α¨α΅αααα αα¬α½α α«α₯α© α₯α α¨α΅α α¨αα³α¨αα α α«α£α’αα ααα© α¨αααα ααα αα«αα’",reply_markup=reply_markup)
else:
message = update.message
current_pos = (message.location.latitude, message.location.longitude)
telegramUserName = update['message']['chat']['first_name']
mycursor = db.mydb.cursor()
mycursor.execute(f"SELECT id FROM clients WHERE userName='{telegramUserName}'")
result = mycursor.fetchall()
for x in result:
id.append(x[0])
username=telegramUserName.lower()+" basket"
mycursor = db.mydb.cursor()
sql =f"SELECT COUNT(food) FROM `{username}`"
mycursor.execute(sql)
myResult=mycursor.fetchall()
for x in myResult:
count[0]=x[0]
if count[0] > 0:
mycursor = db.mydb.cursor()
sql =f"Select * FROM `{username}`"
mycursor.execute(sql)
myResult=mycursor.fetchall()
keyboard =[]
for x in myResult:
food_price[0] = food_price[0] + int(x[3])
food_holder.append(x[1])
food_holder.append(x[2])
direction = driver.find_element_by_id("xoLGzf-T3iPGc")
direction.send_keys(Keys.RETURN)
try:
your_location = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH,"//div[@id='sb_ifc51']/input[1]"))
)
driver.find_element_by_xpath("//div[@id='sb_ifc51']/input[1]").clear()
your_location.send_keys(f"{current_pos[0]},{current_pos[1]}")
your_Destination = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH,"//div[@id='sb_ifc52']/input[1]"))
)
your_Destination.send_keys(f"{Basket.resturant_name[0].title()}")
your_Destination.send_keys(Keys.RETURN)
detail = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.ID,"section-directions-trip-details-msg-0"))
)
driver.find_element_by_id("section-directions-trip-details-msg-0").click()
km = WebDriverWait(driver, 5).until(
EC.presence_of_element_located((By.XPATH, "html/body/div[3]/div[9]/div[8]/div/div/div/div/div[3]/div/h1/span/span[2]/span"))
)
dis = driver.find_element_by_xpath("html/body/div[3]/div[9]/div[8]/div/div/div/div/div[3]/div/h1/span/span[2]/span").text
print(f"Distance: {dis}")
distance = dis.replace('km','')
print(f"Distance: {distance}")
distance = distance.strip()
distance = int(distance)
print(f"Dist: {distance}")
except:
print("Exception Error")
mycursor = db.mydb.cursor()
mycursor.execute(f"SELECT Distance,Price FROM deliverfee")
result = mycursor.fetchall()
for x in result:
distanceInString = x[0]
if len(distanceInString) == 3:
if float(distance) >= int(distanceInString[0]) and float(distance) < int(distanceInString[2]):
deliveryFee[0] = x[1]
break
elif len(distanceInString) == 4:
if float(distance) >= int(distanceInString[0]) and float(distance) < (int(f"{distanceInString[2]}{distanceInString[3]}")):
deliveryFee[0] = x[1]
break
elif len(distanceInString) == 5:
if float(distance) >= int(distanceInString[0]) and float(distance) < (int(f"{distanceInString[3]}{distanceInString[4]}")):
deliveryFee[0] = x[1]
print(f"Deliver Fee: {deliveryFee[0]}")
break
totalPrice[0] = int(deliveryFee[0]) + food_price[0]
newline="\n"
reply_markup = InlineKeyboardMarkup(keyboard)
print(food_holder)
update.message.reply_text(f"α΅ααα\n\nπ€ αα³ααα« αα₯α: {id[0]}\n\nααα₯ α€α΅: {Basket.resturant_name[0].title()}\n\nααα¦α½:\n\n{newline.join(str(x) for x in food_holder)}\n\nα α
αα α¨ααα₯ αα: {food_price[0]} α₯α\nπ α¨αααͺα« ααα«: {int(deliveryFee[0])} α₯α\nπ΅ α α
αα αα: {totalPrice[0]} α₯α",reply_markup=reply_markup)
id.pop()
totalPrice[0] = 0
food_price[0] = 0
# deliveryFee[0] = 0
keyboard = [['π αααα΅', 'π αααα£α΅ α αα'],['α¦α±α α₯αα°αα α«α΅ααα©']]
message = "ααα‘α ααα α₯αα°αααα α₯ααα α α¨αα α₯α£ααα π αααα΅ α¨αααα ααα α«α΅αα α₯ααα α α«ααα π αααα£α΅ α αα α¨αααα ααα α«α΅αα"
reply_markup = ReplyKeyboardMarkup(keyboard,one_time_keyboard=True,resize_keyboard=True)
update.message.reply_text(message, reply_markup=reply_markup)
driver.back()
driver.back()
checkers.pop()