Beispiel #1
0
def add_entry():
    # clean the entered phone number
    newPhone = cleanphone(request.form['phone'])
    # did we get a valid number?????
    if newPhone != '-1':
        db_session.add(Numbers(newPhone))
        db_session.commit()
        # Find the numbers that do not have a buddy
        newBud = db_session.query(Numbers).filter(Numbers.buddy==None, Numbers.phone != newPhone).first()
        if newBud:
            # Add the buddy number to the newly added phone number
            db_session.query(Numbers).filter(Numbers.phone==newPhone).update({Numbers.buddy: newBud.phone})
            # Add the number to the buddy list 
            db_session.query(Numbers).filter(Numbers.phone==newBud.phone).update({Numbers.buddy: newPhone})
            db_session.commit()
            body = "Thanks for signing up! You've been matched with a buddy. You can text this number to start sharing!"
            send_sms(newPhone, body)
            send_sms(newBud.phone, body)
            return redirect(url_for('index'))
        else:
            body = "Thanks for signing up! We're still waiting to match you. We'll contact you when we get a match, usually in a day or two."
            send_sms(newPhone, body)
            return redirect(url_for('index'))

    else:
        flash('Sorry that is not a valid number')
        return redirect(url_for('index'))
Beispiel #2
0
def add_entry_text(newNumber):
    if newNumber:
        newPhone = newNumber
    else:
        newPhone = cleanphone(request.form['phone'])
    db_session.add(Numbers(newPhone))
    db_session.commit()
    # Find the numbers that do not have a buddy
    newBud = db_session.query(Numbers).filter(Numbers.buddy==None, Numbers.phone != newPhone).first()
    if newBud:
        # Add the buddy number to the newly added phone number
        db_session.query(Numbers).filter(Numbers.phone==newPhone).update({Numbers.buddy: newBud.phone})
        # Add the number to the buddy list 
        db_session.query(Numbers).filter(Numbers.phone==newBud.phone).update({Numbers.buddy: newPhone})
        db_session.commit()
        body = "Thanks for signing up! You've been matched with a buddy. You can text 415.697.3084 to start sharing!"
        send_sms(newPhone, body)
        send_sms(newBud.phone, body)
    else:
        body = "Thanks for signing up! We're still waiting to match you. We'll contact you when we get a match, usually in a day or two."
        send_sms(newPhone, body)