Beispiel #1
0
    def save(self):
        """ Saves to SQLAlchemy User and Snipe models """

        snipe = Snipe.create(self.email.data, self.section.data)

        db.session.add(snipe)
        db.session.commit()
Beispiel #2
0
    def save(self):
        """ Saves to SQLAlchemy User and Snipe models """

        snipe = Snipe.create(self.email.data, self.subject.data, self.course_number.data, self.section.data)

        db.session.add(snipe)
        db.session.commit()
Beispiel #3
0
    def save(self):
        """ Saves to SQLAlchemy User and Snipe models """

        # Remove '+1's from phone numbers
        self.phone_number.data = self.phone_number.data.lstrip('+1')
        snipe = Snipe.create(self.phone_number.data, self.email.data, self.subject.data, self.course_number.data, self.section.data)

        db.session.add(snipe)
        db.session.commit()
Beispiel #4
0
def twilio_callback():
    """ Handles the callback from twilio """
    course_info = request.form['Body']

    # Regex to search for subject:course_num:section in the text message.
    m = re.search('([\w\d]+):([\w\d]+):([\w\d]+)', course_info)
    if m:
        subject = m.group(1)
        course_number = m.group(2)
        section = m.group(3)

        # Twilio always puts +1s at the beginning of phone numbers
        phone_number = request.form['From'].lstrip('+1')

        # check if the user already exists
        user = User.query.filter_by(phone_number=phone_number).first()
        if user:
            email = user.email
        else:
            email = None


        snipe = Snipe.create(phone_number, email, subject, course_number, section)

        db.session.add(snipe)
        db.session.commit()

        # Notify the user via text message.
        text = "I'm on it. Watching %s:%s:%s for you." % (subject, course_number, section)
        client.sms.messages.create(to=snipe.user.phone_number, from_="+17326384545", body=text)

        return '<Response></Response'
    else:
        # log errors.
        app.logger.error('There is sadness with text messages')
        app.logger.error('Message: %s Other %s' % (request.form['Body'], str(request.form)))

        return '<Response></Response>'