Skip to content

Instantly share code, notes, and snippets.

@AhsanSN
Created March 11, 2020 07:10
Show Gist options
  • Save AhsanSN/354630cab64e1ad0b25295006dcfcc5f to your computer and use it in GitHub Desktop.
Save AhsanSN/354630cab64e1ad0b25295006dcfcc5f to your computer and use it in GitHub Desktop.
import requests
import json, os
from threading import Timer
currentBookingInfo = "";
currentLocation = [1,1];
def getNextBookingDetails(currentBookingId):
URL = "http://ventoms.com/anomoz/swift/post/read_new_booking.php?currentBookingId="+str(currentBookingId)
r = requests.get(url = URL)
# extracting data in json format
data = r.json()
info = (data[0])
return info
def markBookingAsEnded(currentBookingId):
URL = "http://ventoms.com/anomoz/swift/post/mark_booking_as_ended.php?currentBookingId="+str(currentBookingId)
r = requests.get(url = URL)
return True
def getPickupLocation(currentBookingInfo):
print("getPickupLocation set: ", [currentBookingInfo["fromLocation_lat"], currentBookingInfo["fromLocation_lng"]])
return([currentBookingInfo["fromLocation_lat"], currentBookingInfo["fromLocation_lng"]])
def getFinalLocation(currentBookingInfo):
print("getFinalLocation set: ", [currentBookingInfo["toLocation_lat"], currentBookingInfo["toLocation_lng"]])
return([currentBookingInfo["toLocation_lat"], currentBookingInfo["toLocation_lng"]])
def startNavigator(currentLocation, destination):
programCommand = "rosrun simple_navigation_goals simple_navigation_goals _param_x:="+str(destination[0])+" _param_y:="+str(destination[1])
if os.system(programCommand) == 0:
print("program finished successfully")
else:
print("launch failed")
def generateExe():
if os.system("g++ -g foo.cpp -o foo") == 0:
print ("exe compiled")
else:
print ("exe compiling Failed")
def runSingleCycle():
currentBookingInfo = getNextBookingDetails(0)
#currentBookingInfo = {'bookingId': '187', 'timeAdded': '1573634449', 'fromLocation': 'Auditorium', 'toLocation': 'Auditorium', 'fromPerson': 'Dr. taj', 'toPerson': 'Dddx', 'status': 'waiting', 'fromLocation_lat': '-9.656250', 'fromLocation_lng': '5.750000', 'toLocation_lat': '-9.656250', 'toLocation_lng': '5.750000'}
print("currentBookingInfo updated: ", currentBookingInfo)
#go to pickup location
pickupLocation = getPickupLocation(currentBookingInfo)
startNavigator(currentLocation, pickupLocation) #program stops until
#open lock for pickup
#to to destination
dropoffLocation = getFinalLocation(currentBookingInfo)
startNavigator(currentLocation, dropoffLocation)
#openlock for dropoff
#mark booking
markBookingAsEnded(currentBookingInfo['bookingId'])
return
def twoArgs(arg1,arg2):
print (arg1)
print ("")
def main():
r = Timer(1.0, twoArgs, ("Ahsan Ahmed","arg2"))
r.start()
return 0
#generateExe()
#runSingleCycle()
#get next booking Status
main()
@AhsanSN
Copy link
Author

AhsanSN commented Mar 11, 2020

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, World!"
    
@app.route("/openlock")
def openlock():
    return "lock opened"
    
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=4010)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment