예제 #1
0
파일: views.py 프로젝트: zelliott/PennCycle
def reply(message):
    reply = twilio.twiml.Response()
    if len(message) > 160:
        message = message[:160]
        email_razzi("Long message. {}".format(message))
    reply.sms(message)
    return reply
예제 #2
0
파일: views.py 프로젝트: zelliott/PennCycle
def handle_checkin(student, body):
    # Make sure they actually have a bike out
    if not student.ride_set.filter(checkin_time=None):
        try:
            ride = student.ride_set.latest("checkin_time")
        except:
            return "You have never checked out a bike. Check out a bike using the 'checkout (number)'. Once you have done that, use this command to return it."

        checkin_display_time = timezone.localtime(ride.checkin_time)
        time_of_day = "{}:{}".format(checkin_display_time.hour, checkin_display_time.minute)
        return "You don't have any rides to check in. Your last ride was checked in at {} at {}.".format(time_of_day, ride.checkin_station)

    # Get their location and check the bike in
    location = None
    stations = Station.objects.all()
    for station in stations:
        if station.name.lower() in body or (station.full_name and station.full_name.lower() in body):
            location = station
    if not location:
        email_razzi("Station didn't match for checkin. Message was {}".format(body))
        message = "Station not found. Options: Rodin, Ware, Huntsman, Fisher, College Hall, Hill, PSA. To return text 'Checkin Hill' or another station."
        return message
    ride = student.ride_set.latest("checkout_time")
    checkin_ride(ride, location)
    message = "You have successfully returned your bike at {}. Make sure it is locked, and we will confirm the bike's checkin location shortly. Thanks!".format(location)
    return message
예제 #3
0
파일: lend.py 프로젝트: razzius/PennCycle
def checkin_ride(ride, station):
    ride.checkin_time = datetime.datetime.now(pytz.utc)
    ride.checkin_station = station
    ride.bike.status = "available"
    ride.bike.location = station
    try:
        payment = ride.rider.payments.filter(status="out").latest()
    except Exception:
        payment = ride.rider.payments.latest()
        email_razzi("Rider didn't have any payments out")
    payment.status = "available"
    payment.save()
    ride.bike.save()
    ride.save()
예제 #4
0
def checkout(request):
    data = request.POST
    bike = data.get("bike")
    penncard = data.get("penncard")
    pin = data.get("pin")
    try:
        student = Student.objects.get(penncard=penncard)
    except Student.DoesNotExist:
        return json_failure("Student does not exist.")
    if student.pin != pin:
        email_razzi("pin mismatch! {}".format(locals()))
        return HttpResponseForbidden()
    if not student.can_ride:
        message = ""
        current_rides = student.ride_set.filter(checkin_time=None)
        if len(current_rides) > 0:
            bike = current_rides[0].bike.name
            message += "You can't check bikes out until you check bike {} in. ".format(bike)
        if not student.waiver_signed:
            message += "You need to fill out a waiver. Click the 'account' button at the bottom and accept the waiver there. "
        if not student.current_payments:
            message = "You don't currently have any PennCycle plans. Log on to penncycle.org to add one."
        return json_failure(message)
    try:
        bike = Bike.objects.get(name=bike)
    except Exception:
        return json_failure(
            "Bike {} is unavailable."
            .format(bike)
        )
    if bike.status == 'available':
        make_ride(student, bike)
    else:
        return json_failure(
            "Bike {} is unavailable with status '{}'."
            .format(bike.name, bike.status)
        )
    return http_json({"combo": bike.combo})
예제 #5
0
파일: views.py 프로젝트: zelliott/PennCycle
def handle_checkout(student, body):
    if not student.can_ride:
        current_rides = student.ride_set.filter(checkin_time=None)
        if not student.waiver_signed:
            message = "You need to accept our waiver. Go to penncycle.org/signin to do so."
        elif not student.current_payments:
            message = (
                "You don't currently have any PennCycle plans. "
                "Log on to penncycle.org/signin to add one."
            )
        elif len(current_rides) > 0:
            bike = current_rides[0].bike.name
            message = "You can't check bikes out until you check bike {} back in. ".format(bike)
        else:
            message = "You are currently unable to ride. Log in to your penncycle account at penncycle.org/signin to fix this."
            email_razzi("Strange cannot ride case. {}".format(locals()))
        return message
    try:
        bike_number = re.search("\d+", body).group()
    except:
        return "Command not understood. Text 'help' for a list of commands. Example of checking out a bike would be: Checkout 10"
    try:
        bike = Bike.objects.get(name=bike_number)
    except Bike.DoesNotExist:
        message = "Bike not found. Text 'Checkout (number)', where number is 1 or 2 digits. Text 'Report (issue)' to report an issue."
        return message
    if bike.status == "available":
        make_ride(student, bike)
        message = "You have successfully checked out bike {}. The combination is {}. To return it, reply 'Checkin Hill' or any other station. Text 'Stations' for a list.".format(bike_number, bike.combo)
    elif bike.status == "out":
        checkout_time = bike.rides.latest().checkout_time
        time_string = timezone.localtime(checkout_time).strftime("%H:%M on %D")
        message = "Bike {} is still in use. It was checked out at {}. Text 'bikes' for a list of available bikes.".format(bike.name, time_string)
    else:
        message = "Bike {} is not in service. Please try another bike, or text 'bikes' for a list of available bikes.".format(bike.name)
    return message
예제 #6
0
파일: views.py 프로젝트: zelliott/PennCycle
def handle_help(student, body):
    if student.can_ride:
        message = "Checkout: Checkout (number). Checkin: Checkin (location). Text Stations or Bikes for station/bike info. Report (issue) reports an issue. You can check out bikes"
        return message
    else:
        current_rides = student.ride_set.filter(checkin_time=None)
        if len(current_rides) > 0:
            bike = current_rides[0].bike.name
            message = "You have bike {} out. Until you return it, you can't check out bikes. Text 'locations' for checkin stations and 'report' to report an issue.".format(bike)
        elif not student.waiver_signed:
            email_razzi("Waiver not signed by {} on sms.".format(student))
            message = "You need to fill out a waiver. Log on to www.penncycle.org/signin to do so."
        else:
            email_razzi("{} doesn't have any payments, it would seem. Contact him at {}".format(student.name, student.email))
            message = "You are unable to check out bikes. Go to penncycle.org/signin and enter your penncard to check your status. You must purchase a plan before you can ride."
        if not any(command in body for command in ["help", "info", "information", "?"]):
            email_razzi("Body didn't match command. {}".format(locals()))
        return message
예제 #7
0
def report(request):
    data = request.POST
    penncard = data.get("penncard")
    feedback = data.get("message")
    email_razzi("Got feedback: {} from {}".format(feedback, penncard))
    return HttpResponse()