from twilio.rest import TwilioRestClient
from flask import Flask, request, redirect
import twilio.twiml
from uberpy import Uber
from geopy.geocoders import Nominatim
import pdb

SECRET_KEY = "asdfasdfasdf"

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "AC50a25b43c9f2c9a844fe0e06a6349303"
auth_token  = "bfdcce4ecda50fa055876750bb165676"
client = TwilioRestClient(account_sid, auth_token)

counter = 0
address = ""
selected_uber = ""
latitude = ""
longitude = ""

messages = [
"Welcome to rideText! What would you like to do?",
#"A 128-bit secured webpage will now open up, where you can enter your username and password",
"Please type in an address or intersection",
"Ubers available:",
"Uber is on the way! Text the keyword 'status' for the status of your uber"
]

keywords = [
"request"
"status",
"cancel"
]

uber = Uber("gnccLgkxBcZJMca3pp9mydlSYaATAAFF", "VxhO24omuwWB-2zy3FXbCjJbpshGokmWdyjffQLY", "hKA5OENDNCaEKPFZDlqbI-YxkeRFbt7DazOVZMK_")

geolocator = Nominatim()
app = Flask(__name__)

@app.route("/", methods=['GET', 'POST'])
def hello():
    global counter
    global address
    global selected_uber
    global latitude
    global longitude
    resp = twilio.twiml.Response()
    response_details = request.values
    body = str(response_details.getlist('Body')[0])
    #pdb.set_trace()
# message to use shortcodes and description in beginning

    if counter == 0:
      resp.message(messages[0])
    if counter == 2:
      selected_uber = body
      resp.message(messages[3])
    if counter == 1:
      address = body
      coords = latitude_longitude(address)
      latitude = coords[0]
      longitude = coords[1]
      counter = 2
      resp.message(messages[2])
      print(uber.get_products(latitude, longitude))
    if body.lower() == "request":
      resp.message(messages[1])
      counter = 1
    if body.lower() == "cancel":
      counter = 0
    if body.lower() == "status":
      uber_status
    return str(resp)

def local_ubers(latitude, longitude):
  return uber.get_products(latitude, longitude)

def latitude_longitude(address):
  location = geolocator.geocode(address)
  return [location.latitude, location.longitude]

def uber_status():
  return 3

if __name__ == "__main__":
    app.run(debug=True)


@@ -487,16 +487,50 @@
 ude = %22%22
+%0Adestination = %22%22%0Adest_coords = %22%22
 %0A%0Amessag
@@ -747,16 +747,48 @@
 able:%22,%0A
+%22Please type in a destination%22,%0A
 %22Uber is
@@ -1180,16 +1180,62 @@
 address%0A
+    global destination%0A    global dest_coords%0A
     glob
@@ -1545,24 +1545,218 @@
 essages%5B0%5D)%0A
+    if counter == 3%0A      destination = body%0A      dest_coords = latitude_longitude(destination)%0A      latitude = dest_coords%5B0%5D%0A      longitude = dest_coords%5B1%5D%0A      resp.message(messages%5B4%5D)%0A
     if count
@@ -1823,12 +1823,30 @@
 ges%5B
-3
+2
 %5D)%0A
+      counter = 3%0A
     
@@ -2019,33 +2019,33 @@
 essage(messages%5B
-2
+3
 %5D)%0A      print(u

Add Destination