Exemplo n.º 1
0
def contact():
    if request.method == 'POST':
        first_name = request.form['firstname']
        last_name = request.form['lastname']
        city = request.form['city']
        comment = request.form['subject']
        star = int(request.form['rating'])
        db, conn1 = connector()
        contact = {
            "First Name": first_name,
            "Second Name": last_name,
            "City": city,
            "Comment": comment,
            "star": star
        }
        error = None
        if not first_name:
            return ('Enter First Name')
        elif not last_name:
            return ('Enter Last Name')
        elif not city:
            return ('Enter the city name')
        elif not comment:
            return ('Enter the Comments')

        if error is None:
            con = db.contact
            con.insert_one(contact)
            return redirect(url_for('auth.auth'))
        flash(error)
    return render_template('auth/contact.html')
Exemplo n.º 2
0
def admin():
    db, conn1 = connector()
    user = db.users
    count1 = user.find().count()
    price = db.activeRides
    cost = list(
        price.aggregate([{
            '$group': {
                '_id': 1,
                'cost': {
                    '$sum': '$trip.route.cost'
                }
            }
        }]))
    user_rating = db.contact
    star = []
    star.append(user_rating.find().count())
    star.append(user_rating.find({"star": 5}).count())
    star.append(user_rating.find({"star": 4}).count())
    star.append(user_rating.find({"star": 3}).count())
    star.append(user_rating.find({"star": 2}).count())
    star.append(user_rating.find({"star": 1}).count())
    print(cost[0])
    admin = db.base_price
    admin_pass = admin.find_one()
    return render_template('AfterLogin/admin_prof.html',
                           admin=admin_pass,
                           cost=cost[0],
                           count1=count1,
                           star=star)
Exemplo n.º 3
0
 def hello():
     try:
         c, conn = connector()
         #print(session['username'])
         return ("okay")
     except Exception as e:
         return (str(e))
Exemplo n.º 4
0
def drivercode():
    client = SinchSMS('826e4cc7-3f6e-4fa2-a9a6-176ccec744c2',
                      'iDeaWwa6S0yMxrTt4ohqcA==')
    db, conn1 = connector()
    mailid = session_name()
    booked = db.bookedRides
    rides = db.offerride
    activeRides = db.activeRides
    codeValue = session.get('code', None)
    starttime = rides.find_one({'mailid': mailid, 'code': codeValue})
    passengerRides = []
    for document in booked.find({
            'route.mailid': mailid,
            'route.time': starttime['Time']
    }):
        passengerRides.append(document)
    if request.method == 'POST':
        phno = booked.find({'route.mailid': mailid})
        for phno in booked.find({'route.mailid': session_name()}):
            phno1 = phno['route']['phno']
            print(phno1)
            number = '+91' + phno1
            print(number)
        number = '+918237822234'
        message = 'Your Ride has started .'
        print("ABC")
        client.send_message(number, message)
        rides.find_one_and_delete({'code': codeValue})
        return redirect(url_for('insidelogin.profile'))
    return render_template('AfterLogin/congrat.html',
                           code=codeValue,
                           time=starttime['Time'],
                           passengerRides=passengerRides)
Exemplo n.º 5
0
def automaticDelete():
    db,conn1 = connector()
    currentTime = datetime.datetime.now()-datetime.timedelta(minutes=11)
    currentTime=currentTime.strftime("%m/%d/%Y %H:%M")
    print("Deleting Rides Which are getting active")
    print(currentTime)
    availableRides = db.offerride
    documentstoTransact =list(availableRides.find({'Time':{'$lt':currentTime}}))
    availableRides.delete_many({'Time':{'$lt':currentTime}})
    print(documentstoTransact)
    if documentstoTransact :
        bookedRides = db.bookedRides
        for document in documentstoTransact:
            ridestoTransfer=[]
            ridestoTransfer.extend(list(bookedRides.find({'route.mailid':document['mailid'],'route.time':document['Time']})))
            if not ridestoTransfer:
                findUsers= db.users
                getUserInfo =findUsers.find_one({'mailid':document['mailid']})
                tempdisplay={}
                tempdisplay['mailid']=getUserInfo['mailid']
                tempdisplay['name']=getUserInfo['name']
                tempdisplay['end']=document['End']
                tempdisplay['start']=document['Start']
                tempdisplay['phno']=getUserInfo['phno']
                tempdisplay['model']=getUserInfo['car_details'][0]['model']
                tempdisplay['plate']=getUserInfo['car_details'][0]['plate']
                tempdisplay['cost']= ceil(0)
                tempdisplay['time']=document['Time']
                tempdisplay['code']=document['code']
                activeRides = db.activeRides
                makeBooked = {'mailid':"-",'route':tempdisplay,'start':"-"}
                activeRides.insert_one({'trip':makeBooked})
                print(makeBooked)
Exemplo n.º 6
0
def register():
    if request.method == 'POST':
        username = request.form['name']
        password = request.form['password']
        email = request.form['email']
        phnumber = request.form['Phno']
        confpass = request.form['conpassword']
        car_plate = request.form['plate']
        licence_number = request.form['license']
        car_model = request.form['model']

        if not request.form.get('owncar'):
            car_plate = None
            licence_number = None
            car_model = None
        db, conn1 = connector()
        count1 = db.users.count()
        count1 += 1
        userinfo = {
            "name":
            username,
            "mailid":
            email,
            "password":
            generate_password_hash(password),
            "phno":
            phnumber,
            "car_details": [{
                "model": car_model,
                "plate": car_plate,
                "license": licence_number
            }]
        }
        checkduplicate = db.users.find_one({"mailid": email})

        error = None
        if not username:
            return ('1')
        elif not password:
            return ('2')
        elif not email:
            return ('3')
        elif not phnumber:
            return ('4')
        elif confpass != password or not password:
            return ('5')
        elif checkduplicate is not None:
            #return('User {} is already registered.'.format(username))
            return render_template("auth/signup.html", check=0)
        if error is None:
            user = db.users
            user.insert_one(userinfo)
            return redirect(url_for('auth.login'))
        flash(error)

    return render_template('auth/signup.html')
Exemplo n.º 7
0
def admincontrol():
    db, conn1 = connector()
    user = db.users
    if request.method == 'POST':
        del_user = request.form['username']
        user_check = user.find_one({'mailid': del_user})
        if user_check is None:
            return render_template('AfterLogin/admin_delete.html', exists=0)
        user.find_one_and_delete({'mailid': del_user})
    return render_template('AfterLogin/admin_delete.html')
Exemplo n.º 8
0
def mytrips():
    db, conn1 = connector()
    bookedRides = db.bookedRides
    passengerRides = []
    for document in bookedRides.find({'mailid': session_name()}):
        passengerRides.append(document)
    if request.method == 'POST':
        return redirect(url_for('insidelogin.passengercode'))
    return render_template('AfterLogin/mytrips.html',
                           passengerRides=passengerRides)
Exemplo n.º 9
0
def adminprice():
    db, conn1 = connector()
    admin = db.base_price
    if request.method == 'POST':
        base_price1 = request.form['quantity']
        per_km1 = request.form['quantity1']
        admin.update({},
                     {'$set': {
                         "base_price": base_price1,
                         "per_km": per_km1
                     }})
    return render_template('AfterLogin/admin_cost.html')
Exemplo n.º 10
0
def ridehistory():
    db, conn1 = connector()
    activeRides = db.activeRides
    rideHistory1 = []
    rideHistory2 = []
    for document in activeRides.find({'trip.mailid': session_name()}):
        rideHistory1.append(document)
    for document1 in activeRides.find({'trip.route.mailid': session_name()}):
        rideHistory2.append(document1)

    return render_template('AfterLogin/history.html',
                           ridehistory1=rideHistory1,
                           ridehistory2=rideHistory2)
Exemplo n.º 11
0
def offerhistory():
    db, conn1 = connector()
    activeRides = db.activeRides
    rides = db.offerride
    history1 = []
    for document in rides.find({'mailid': session_name()}):
        history1.append(document)
    if request.method == 'POST':
        print(history1)
        offerOption = int(request.form['offeroption'])
        code = history1[offerOption]['code']
        session['code'] = code
        return redirect(url_for('insidelogin.drivercode'))
    return render_template('AfterLogin/offerhistory.html', history1=history1)
Exemplo n.º 12
0
def cardeets():
    if request.method == 'POST':
        mailid1 = session_name()
        plate = request.form['plate']
        model = request.form['model']
        license = request.form['license']

        db, conn1 = connector()
        user = db.users
        user.update_many({"mailid": mailid1}, {
            '$set': {
                "car_details.0.plate": plate,
                "car_details.0.model": model,
                "car_details.0.license": license
            }
        })
        return redirect(url_for('insidelogin.profile'))
    return render_template('auth/cardeets.html')
Exemplo n.º 13
0
def profile():
    mailid = session_name()
    db, conn1 = connector()
    users = db.users
    user_prof = users.find_one({'mailid': mailid})
    car = users.find({'mailid': mailid}, {'_id': 0, 'car_details': 1})
    plate = car[0]['car_details'][0]['plate']
    model = car[0]['car_details'][0]['model']
    license = car[0]['car_details'][0]['license']
    user_details = {
        'Name': user_prof['name'],
        'email': mailid,
        'Mobile_No': user_prof['phno'],
        'Car_Number': plate,
        'Car_Model': model,
        'licence_Number': license
    }
    session['norides'] = -1
    return render_template('AfterLogin/index.html', user=user_details)
Exemplo n.º 14
0
def takeRoute():
    if request.method == 'POST':
        mailid1 = session_name()
        place1 = request.form['Start']
        place2 = request.form['End']
        date = request.form['Date']
        code = id_generator()
        routeinfo = {
            "mailid": mailid1,
            "Start": place1,
            "End": place2,
            "Time": date,
            "Distance_flex": None,
            "Time_flex": None,
            "No_of_persons": None,
            "waypoints": "",
            "code": code
        }
        db, conn1 = connector()

        session['routeinfo'] = str(routeinfo)
        if request.form['Ride'] == 'Book Ride':
            if session.get('norides', None) == -1:
                return redirect(url_for('afterbookride.showRides'))
            else:
                return render_template('AfterLogin/Begin.html', check=12)
        elif request.form['Ride'] == 'Offer Ride':
            user = db.users
            print("In offer Ride")
            car = user.find({'mailid': mailid1}, {'_id': 0, 'car_details': 1})
            plate = car[0]['car_details'][0]['plate']
            print(plate)
            if plate == None:
                return render_template('AfterLogin/Begin.html', check=0)
            ride = db.offerride
            ride.insert_one(routeinfo)
            #print(session['username'])
            session['time'] = routeinfo['Time']
            print("Going to slider")
            return redirect(url_for('insidelogin.update'))

    return render_template('AfterLogin/Begin.html')
Exemplo n.º 15
0
def login():
    if request.method == 'POST':
        db, conn1 = connector()
        users = db.users

        login_user = users.find_one({'mailid': request.form['email']})
        if login_user is None:
            return render_template('auth/login.html', check=0)
        if login_user['mailid'] == "*****@*****.**":
            password = request.form['password']
            if check_password_hash(login_user['password'], password):
                session['username'] = request.form['email']
                return redirect(url_for('insidelogin.admin'))
        if login_user:
            password = request.form['password']
            if check_password_hash(login_user['password'], password):
                session['username'] = request.form['email']
                return redirect(url_for('auth.index'))
            return render_template('auth/login.html', check=0)
        return render_template('auth/login.html', check=0)

    return render_template('auth/login.html')
Exemplo n.º 16
0
def update():
    if request.method == 'POST':
        db, conn1 = connector()
        mailid1 = session_name()
        admin = db.base_price
        admin.update({}, {'$inc': {'No_of_offers': 1}})
        distance = int(request.form['slider1'])
        time = 100 - distance
        persons = int(request.form['seats'])

        ride = db.offerride
        ride.update_many({
            "mailid": mailid1,
            "Time": session.get('time', None)
        }, {
            '$set': {
                "Distance_flex": distance,
                "Time_flex": time,
                "No_of_persons": persons
            }
        })
        return redirect(url_for('insidelogin.offerhistory'))
    return render_template('AfterLogin/offerRide.html')
Exemplo n.º 17
0
def passengercode():
    mailid = session_name()
    db, conn1 = connector()
    activeRides = db.activeRides
    bookedRides = db.bookedRides
    if request.method == 'POST':
        code = request.form['code1']
        match = bookedRides.find_one({'route.code': code})
        if match is None:
            return render_template('AfterLogin/yay.html', match=0)
        else:
            passengerActiveRide = bookedRides.find_one({
                'mailid':
                match['mailid'],
                'mailid':
                mailid
            })
            activeRides.insert_one({'trip': passengerActiveRide})
            bookedRides.find_one_and_delete({
                'mailid': match['mailid'],
                'mailid': mailid
            })
            return redirect(url_for('insidelogin.profile'))
    return render_template('AfterLogin/yay.html')
Exemplo n.º 18
0
def showRides():
    passroute = ast.literal_eval(session['routeinfo'])
    #passroute= (passroute)
    print(passroute)
    db, conn1 = connector()
    rides = db.offerride
    originPassenger = passroute['Start']
    destinationPassenger = passroute['End']
    base = 'https://maps.googleapis.com/maps/api/directions/json?'
    displayrides = []
    waypointsList = []
    api_key = 'AIzaSyDsDBCYF8CBpzPI4kE7PxqtuQBoLVv2Crc'
    # request to calculate cost
    requestCost = base + urllib.parse.urlencode({
        'origin': originPassenger,
        'destination': destinationPassenger,
        'key': api_key
    })
    responseCost = urllib.request.urlopen(requestCost).read()
    directionCost = json.loads(responseCost.decode('utf-8'))
    routesCost = directionCost['routes']
    legsCost = routesCost[0]['legs']
    distanceCost = []
    for index in range(len(legsCost)):
        distanceCost.append(legsCost[index]['distance']['value'])
    total_distance_cost = float(sum(distanceCost)) / 1000
    totalCost = 15
    if total_distance_cost > 1:
        totalCost += (total_distance_cost - 1) * 5

    for document in rides.find({"End": destinationPassenger}):
        a = dt.strptime(document['Time'], "%m/%d/%Y %H:%M")
        b = dt.strptime(passroute['Time'], "%m/%d/%Y  %H:%M")
        print(a)
        print(b)
        if a > b:
            continue
        if document['mailid'] == session_name():
            continue
        originDriver = document['Start']
        destinationDriver = document['End']
        originalWaypoints = document['waypoints']
        print("Toshal")
        requestChecker = base + urllib.parse.urlencode({
            'origin': originDriver,
            'destination': originPassenger,
            'waypoints': originalWaypoints,
            'key': api_key
        })
        responseCheck = urllib.request.urlopen(requestChecker).read()
        directionCheck = json.loads(responseCheck.decode('utf-8'))
        routesCheck = directionCheck['routes']
        legsCheck = routesCheck[0]['legs']
        distanceCheck = []
        durationCheck = []
        for index in range(len(legsCheck)):
            distanceCheck.append(legsCheck[index]['distance']['value'])
            durationCheck.append(legsCheck[index]['duration']['value'])
        total_distance_check = float(sum(distanceCheck)) / 1000
        total_time_check = timedelta(seconds=sum(durationCheck))
        startDriver = a
        startPassenger = b
        print("Toshal")
        if startDriver + total_time_check > startPassenger:
            continue
        else:
            addedWaypoints = originalWaypoints + '|' + originPassenger
            requestDriver = base + urllib.parse.urlencode({
                'origin': originDriver,
                'destination': destinationDriver,
                'key': api_key
            })
            requestTotal = base + urllib.parse.urlencode({
                'origin': originDriver,
                'destination': destinationDriver,
                'waypoints': addedWaypoints,
                'key': api_key
            })
            responseOne = urllib.request.urlopen(requestDriver).read()
            responseTwo = urllib.request.urlopen(requestTotal).read()

            directionOne = json.loads(responseOne.decode('utf-8'))
            directionTwo = json.loads(responseTwo.decode('utf-8'))

            #print(directionOne)
            #print(directionTwo)

            routesOne = directionOne['routes']
            legsOne = routesOne[0]['legs']
            distanceOne = []
            durationOne = []
            for index in range(len(legsOne)):
                distanceOne.append(legsOne[index]['distance']['value'])
                durationOne.append(legsOne[index]['duration']['value'])

            total_distance_one = float(sum(distanceOne)) / 1000
            total_distance_one = round(total_distance_one, 1)
            total_time_one = timedelta(seconds=sum(durationOne))
            totalDurationOne = sum(durationOne)
            print(total_distance_one, 'km')
            print(str(total_time_one))

            routesTwo = directionTwo['routes']
            legsTwo = routesTwo[0]['legs']
            distanceTwo = []
            durationTwo = []
            for index in range(len(legsTwo)):
                distanceTwo.append(legsTwo[index]['distance']['value'])
                durationTwo.append(legsTwo[index]['duration']['value'])

            total_distance_two = float(sum(distanceTwo)) / 1000
            total_distance_two = round(total_distance_two, 1)
            total_time_two = timedelta(seconds=sum(durationTwo))
            totalDurationTwo = sum(durationTwo)
            print(total_distance_two, 'km')
            print(str(total_time_two))

            distanceFlex = document['Distance_flex']
            timeFlex = document['Time_flex']
            newDistanceFlex = round((total_distance_two - total_distance_one) /
                                    total_distance_one * 100)
            newTimeFlex = round(
                (totalDurationTwo - totalDurationOne) / totalDurationOne * 100)
            if newDistanceFlex > distanceFlex:
                print("rejected")
                continue
            elif newTimeFlex > timeFlex:
                print("rejected")
                continue

            print(total_distance_two, 'km')
            print(str(total_time_two))
            #section after validation
            totalCost += (total_distance_two - total_distance_one) * 5
            findUsers = db.users
            getUserInfo = findUsers.find_one({'mailid': document['mailid']})
            print(getUserInfo)

            tempdisplay = {}
            tempdisplay['mailid'] = getUserInfo['mailid']
            tempdisplay['name'] = getUserInfo['name']
            tempdisplay['end'] = document['End']
            tempdisplay['start'] = document['Start']
            tempdisplay['phno'] = getUserInfo['phno']
            tempdisplay['model'] = getUserInfo['car_details'][0]['model']
            tempdisplay['plate'] = getUserInfo['car_details'][0]['plate']
            tempdisplay['cost'] = ceil(totalCost)
            tempdisplay['time'] = document['Time']
            tempdisplay['code'] = document['code']
            #print(tempdisplay)
            displayrides.append(tempdisplay)
            waypointsList.append(addedWaypoints)

    if len(displayrides) == 0:
        session['norides'] = 1
        return redirect(url_for('insidelogin.takeRoute'))
    else:
        session['norides'] = 0
    if request.method == 'POST':
        rideOption = int(request.form['rides'])
        admin = db.base_price
        admin.update({}, {'$inc': {'No_of_books': 1}})
        bookedRides = db.bookedRides
        bookedRides.insert_one({
            'mailid': session_name(),
            'route': displayrides[rideOption],
            'start': originPassenger
        })
        rides.find_one_and_update(
            {
                'mailid': displayrides[rideOption]['mailid'],
                "Time": displayrides[rideOption]['time']
            }, {'$inc': {
                'No_of_persons': -1
            }})
        rides.find_one_and_update(
            {
                'mailid': displayrides[rideOption]['mailid'],
                "Time": displayrides[rideOption]['time']
            }, {'$set': {
                'waypoints': waypointsList[rideOption]
            }})
        # Check if ride is full and if full add kilometers to admin kilometers
        fullRide = rides.find_one({
            'mailid': displayrides[rideOption]['mailid'],
            'No_of_persons': 0
        })
        if fullRide != None:
            requestCalculate = base + urllib.parse.urlencode(
                {
                    'origin': fullRide['Start'],
                    'destination': fullRide['End'],
                    'waypoints': fullRide['waypoints'],
                    'key': api_key
                })
            responseCalculate = urllib.request.urlopen(requestCalculate).read()
            directionCalculate = json.loads(responseCheck.decode('utf-8'))
            routesCalculate = directionCalculate['routes']
            legsCalculate = routesCalculate[0]['legs']
            distanceCalculate = []
            for index in range(len(legsCalculate)):
                distanceCalculate.append(
                    legsCalculate[index]['distance']['value'])
            total_distance_calculate = float(sum(distanceCalculate)) / 1000
            updateKilometer = db.base_price
            admin = updateKilometer.find_one()
            modifiedKilometer = total_distance_calculate + admin['total_dist']
            print(modifiedKilometer)
            updateKilometer.update({},
                                   {'$set': {
                                       'total_dist': modifiedKilometer
                                   }})
        rides.delete_one({
            'mailid': displayrides[rideOption]['mailid'],
            'No_of_persons': 0
        })
        return redirect(url_for('insidelogin.passengercode'))

        #waypoints.append('Swargate')
        #waypoints.append('Baner')

    return render_template('AfterLogin/disprides.html',
                           displayrides=displayrides)