コード例 #1
0
    def test_respond_message_contains_message_element(self):
        # arrange
        twilio_services = TwilioServices()
        # act
        message = "Message"
        response = str(twilio_services.respond_message(message))
        twiml = ElementTree.fromstring(response)

        # assert
        assert twiml.findall("./Message/Body")[0].text == message
コード例 #2
0
    def message():
        subscriber = Subscriber.query.filter(Subscriber.phone_number == request.form['From']).first()
        if subscriber is None:
            subscriber = Subscriber(phone_number=request.form['From'])
            db.session.add(subscriber)
            db.session.commit()
            output = "Thanks for contacting TWBC! Text 'subscribe' if you would like to receive updates via text message."
        else:
            output = _process_message(request.form['Body'], subscriber)
            db.session.commit()

        twilio_services = TwilioServices()
        return twiml(twilio_services.respond_message(output))
コード例 #3
0
    def message():
        subscriber = Subscriber.query.filter(
            Subscriber.phone_number == request.form['From']).first()
        if subscriber is None:
            subscriber = Subscriber(phone_number=request.form['From'])
            db.session.add(subscriber)
            db.session.commit()
            output = "Thanks for contacting TWBC! Text 'add' if you would like to receive updates via text message."
        else:
            output = _process_message(request.form['Body'], subscriber)
            db.session.commit()

        twilio_services = TwilioServices()
        return twiml(twilio_services.respond_message(output))
コード例 #4
0
    def message():
        subscriber = Subscriber.query.filter(
            Subscriber.phone_number == request.form['From']).first()
        if subscriber is None:
            subscriber = Subscriber(phone_number=request.form['From'])
            db.session.add(subscriber)
            db.session.commit()
            output = "Thanks for contacting the UCI parent text message study. Text " \
                     "\"subscribe\" if you would like to receive updates via text message in English. " \
                     "Gracias por contactar el estudio conducido por UCI, el mensaje de texto para los padres. " \
                     "Responde con un mensaje de texto con la palabra " \
                     "\"inscribe\" si gustarían recibir notificaciones por mensaje de texto en Español."

        elif not subscriber.subscribed:
            output = _process_message(request.form['Body'], subscriber)
            db.session.commit()

        elif subscriber.zipcode is None and subscriber.spanish:
            output = _process_zip_spanish(request.form['Body'], subscriber)
            db.session.commit()

        elif subscriber.zipcode is None and not subscriber.spanish:
            output = _process_zip(request.form['Body'], subscriber)
            db.session.commit()

        elif subscriber.age is None and subscriber.spanish:
            output = _process_age_spanish(request.form['Body'], subscriber)
            db.session.commit()

        elif subscriber.age is None and not subscriber.spanish:
            output = _process_age(request.form['Body'], subscriber)
            db.session.commit()

        elif subscriber.interests is None and subscriber.spanish:
            output = _process_interests_spanish(request.form['Body'],
                                                subscriber)
            db.session.commit()

        elif subscriber.interests is None and not subscriber.spanish:
            output = _process_interests(request.form['Body'], subscriber)
            db.session.commit()

        else:  # trying to fix the unbound local error message that happens after trying to unsubscribe after signup,
            # this fixes it
            output = _process_message(request.form['Body'], subscriber)
            db.session.commit()

        twilio_services = TwilioServices()
        return twiml(twilio_services.respond_message(output))
コード例 #5
0
    def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate_on_submit():
            subscribers = Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number, form.message.data, form.imageUrl.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return view('notifications', form)
コード例 #6
0
    def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate_on_submit():
            subscribers = Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number,
                                                 form.message.data,
                                                 form.imageUrl.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return view('notifications', form)
コード例 #7
0
ファイル: views.py プロジェクト: chenjeffrey23/Comadre-Code-
    def _process_interests(message, subscriber):
        output = "Sorry, that's an invalid interest. Please reenter your child's interests: 1 for science/tech, " \
                 "2 for arts, 3 for sports, 4 for all."

        interestList = message.strip(" ").split(" ")
        for interest in interestList:
            try:
                if 0 > int(interest) > 4:
                    return output
            except:
                return output

        conn = sqlite3.connect(
            'summeropp.db')  # opens DB, DB will be created if it doesn't exist
        conn.text_factory = str
        c = conn.cursor()
        opps = []
        for row in c.execute(
                'SELECT * FROM summer_opportunities WHERE zipcode = ? LIMIT 3',
            [subscriber.zipcode]):
            opps.append(row)

        twilio_services = TwilioServices()
        if len(opps) > 1:
            firstmessage ="You're all set. You'll get info a few times per week on out of school learning "\
                        "opportunities and advice. "
            twilio_services.send_message(subscriber.phone_number, firstmessage)
            try:
                for i in opps:
                    opp = (i[0] + " " + i[1] + " " + i[2] + " " + i[3] + " " +
                           str(i[4]) + " " + i[5] + " " + i[6] + " " + i[7] +
                           " " + i[8] + " " + i[9] + " " + i[10] + " " +
                           i[11] + " " + i[12] + " " + i[13] + " " + i[14] +
                           " " + i[15] + " " + i[16] + " " + i[17] + " " +
                           i[18] + " " + i[19])

                    twilio_services.send_message(subscriber.phone_number, opp)
                subscriber.interests = message
                output = "Above are three opportunities to get you started! Reply \"finished\" " \
                     "at any time to stop these messages and delete your data. " \
                     "Standard text messaging and data rates apply."
            except:
                subscriber.interests = message
                output = "Reply \"finished\" " \
                         "at any time to stop these messages and delete your data. " \
                         "Standard text messaging and data rates apply."
        else:
            subscriber.interests = message
            output = "You're all set. You'll get info a few times per week on out of school learning opportunities "\
                     "and advice. Reply \"finished\" at any time to stop these messages and delete your data. " \
                     "Standard text messaging and data rates apply."
        c.close()
        conn.close()
        return output
コード例 #8
0
ファイル: views.py プロジェクト: chenjeffrey23/Comadre-Code-
    def _process_interests_spanish(message, subscriber):
        output = "Lo sentimos, no reconocemos las areas que les interesan a su/s hijo/a. Porfavor vuelve a ingresar " \
                 "responda con las areas que les interesan a su/s hijo/a."

        interestList = message.strip(" ").split(" ")
        for interest in interestList:
            try:
                if 0 > int(interest) > 4:
                    return output
            except:
                return output

        conn = sqlite3.connect(
            'summeropp.db')  # opens DB, DB will be created if it doesn't exist
        conn.text_factory = str
        c = conn.cursor()
        opps = []
        for row in c.execute(
                'SELECT * FROM summer_opportunities WHERE zipcode = ? LIMIT 3',
            [subscriber.zipcode]):
            opps.append(row)

        twilio_services = TwilioServices()
        if len(opps) > 1:
            firstmessage ="Felicidades, ya se inscribió! Recibirá mensajes semanales con avisos de programas o actividades " \
                 "educativas e informativas."
            twilio_services.send_message(subscriber.phone_number, firstmessage)
            try:
                for i in opps:
                    opp = (i[0] + " " + i[1] + " " + i[2] + " " + i[3] + " " +
                           str(i[4]) + " " + i[5] + " " + i[6] + " " + i[7] +
                           " " + i[8] + " " + i[9] + " " + i[10] + " " +
                           i[11] + " " + i[12] + " " + i[13] + " " + i[14] +
                           " " + i[15] + " " + i[16] + " " + i[17] + " " +
                           i[18] + " " + i[19])

                    twilio_services.send_message(subscriber.phone_number, opp)
                subscriber.interests = message
                output = "Si en algún momento le gustaría finalizar este servicio, responda con la " \
                "palabra \"alto\". Se aplican las tarifas estándar de mensajería de texto y datos. "
            except:
                subscriber.interests = message
                output = "Si en algún momento le gustaría finalizar este servicio, responda con la " \
                "palabra \"alto\". Se aplican las tarifas estándar de mensajería de texto y datos. "
        else:
            subscriber.interests = message
            output = "Felicidades, ya se inscribió! Recibirá mensajes semanales con avisos de programas o actividades " \
                 "educativas e informativas. Si en algún momento le gustaría finalizar este servicio, responda con la " \
                "palabra \"alto\". Se aplican las tarifas estándar de mensajería de texto y datos. "
        c.close()
        conn.close()
        return output
コード例 #9
0
    def notifications():
        form = SendMessageForm()
        if request.method == 'POST' and form.validate():
            flash(form.language.data)
            flash(form.zipCode.data)
            for zip in form.zipCode.data:
                flash(zip.strip('u'))
            flash(form.interest.data)
            for i in form.interest.data:
                flash(i.strip('u'))
            flash(form.childAge.data)
            temp1 = set()
            subscribers = []
            flash(form.message.data)
            for zips in form.zipCode.data:
                if zips != "All":
                    tempzip = int(zips)
                    temp1.update(
                        Subscriber.query.filter(
                            Subscriber.zipcode == tempzip).all())
                else:
                    temp1.update(
                        Subscriber.query.filter(Subscriber.subscribed).all())
            if (form.language.data) == "Spanish":
                temp1.intersection_update(
                    Subscriber.query.filter(Subscriber.spanish).all())
            for i in (form.interest.data):
                if i == "All":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 4).all())
                elif i == "Science/Tech":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 1).all())
                elif i == "Arts":
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 2).all())
                else:
                    temp1.intersection_update(
                        Subscriber.query.filter(
                            Subscriber.interests == 3).all())
            if form.childAge.data != "":
                ages = (form.childAge.data.split(" "))
                for age in ages:
                    if len(temp1) > 0:
                        for subs in temp1:
                            subages = subs.age.split(" ")
                            for subage in subages:
                                if subage == age:
                                    subscribers.append(subs)
            else:
                subscribers = temp1

            #temp2 = Subscriber.query.filter(Subscriber.age == form.childAge.data).all()
            #stemp2 = set(temp2)

            #subscribers= Subscriber.query.filter(Subscriber.subscribed).all()
            if len(subscribers) > 0:
                flash('Messages on their way!')
                twilio_services = TwilioServices()
                for s in subscribers:
                    twilio_services.send_message(s.phone_number,
                                                 form.message.data)
            else:
                flash('No subscribers found!')

            form.reset()
            return view('notifications', form)

        return render_template('notifications.html', form=form)