Coder Social home page Coder Social logo

twiliodeved / appointment-reminders-flask Goto Github PK

View Code? Open in Web Editor NEW
75.0 26.0 34.0 1.45 MB

Use Twilio to send SMS reminders to your customers about upcoming appointments

Home Page: https://www.twilio.com/docs/tutorials/walkthrough/appointment-reminders/python/flask

License: MIT License

Python 73.88% Mako 2.17% HTML 21.53% JavaScript 0.76% Shell 1.66%
twilio-sms

appointment-reminders-flask's Introduction

Twilio

Twilio's Appointment Reminders with Flask

Coverage Status

Use Twilio to send SMS reminders to your customers about upcoming appointments. Learn how appointment reminders help other companies in these Twilio customer stories.

Read the full tutorial here!

Quickstart

Local development

This project is built using the Flask web framework. It runs on Python 2.7+ and Python 3.4+.

To run the app locally, first clone this repository and cd into its directory. Then:

  1. Create and activate a new python3 virtual environment.

    python3 -m venv venv
    source venv/bin/activate
  2. Install the requirements using pip.

    pip install -r requirements.txt
  3. Copy the .env.example file to .env and add the following values. Be sure to replace the placeholders and connection string with real information.

    SECRET_KEY = 'your_authy_secret_key'
    
    TWILIO_ACCOUNT_SID = '[your_twilio_account_sid]'
    TWILIO_AUTH_TOKEN = '[your_twilio_auth_token]'
    TWILIO_NUMBER = '[your_twilio_phone_number]'
    
  4. Create Flask application variables

    export FLASK_APP=reminders 
    export FLASK_ENV=development
  5. Run the migrations.

    flask db upgrade
  6. Start a redis server to be our Celery broker. If on a Mac, we recommend installing redis through homebrew If you already have docker installed in your system an easy way of get redis running is:

    docker run -d -p 6379:6379 redis:latest
  7. Start the development server:

    flask run

You can now access the application at http://localhost:5000. To send any reminders, however, you must also start a separate Celery worker process.

  1. Start a new terminal session, cd into the repository, and active your appointment-reminders virtualenv

  2. Activate Flask development environment

    export FLASK_ENV=development
  3. Start the Celery worker:

    celery -A tasks.celery worker -l info

Celery will now send SMS reminders for any new appointments you create through the web app.

Run the tests

You can run the tests locally. Follow the instructions in the Local Development section above, and then run:

python runtests.py

You can then view the results with coverage report or build an HTML report with coverage html.

Meta

  • No warranty expressed or implied. Software is as is. Diggity.
  • MIT License
  • Lovingly crafted by Twilio Developer Education.

appointment-reminders-flask's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appointment-reminders-flask's Issues

Write a test for the Celery task

Right now the test coverage for the app is pretty good - 91% by my measurement:

Name                           Stmts   Miss  Cover
--------------------------------------------------
application                       46      3    93%
config/__init__                    0      0   100%
forms/__init__                     0      0   100%
forms/new_appointment             13      0   100%
models/__init__                    0      0   100%
models/appointment                24      1    96%
reminders                          6      0   100%
runapp                             2      2     0%
tasks                             17      7    59%
tests/appointment_test            31      0   100%
views/__init__                     0      0   100%
views/appointment                 32      3    91%
--------------------------------------------------
TOTAL                            171     16    91%

We don't have a test that covers the task module well, however:

image

Since this is an important part of the app, we should definitely cover it with at least one test.

The CELERY_ALWAYS_EAGER setting is helpful for running tests because it forces Celery to execute tasks synchronously instead of sending them to the message broker:

http://docs.celeryproject.org/en/2.5/configuration.html?highlight=celery_always_eager#std:setting-CELERY_ALWAYS_EAGER

I didn't use py.test in my Django unit tests, but my code for testing the Celery task in that app might still be helpful as you write yours:

https://github.com/TwilioDevEd/appointment-reminders-django/blob/master/reminders/tests.py#L89-L112

Change Heroku button to use offiical Heroku Redis instead of RedisToGo

Starting up the app via Heroku worked perfectly for me.

If possible, I think it would be better if we used the recently released official Heroku Redis addon instead of RedisToGo:

https://addons.heroku.com/heroku-redis?utm_campaign=search&utm_medium=dashboard&utm_source=addons

When I was building the appointment-reminders-django tutorial, my Heroku button deploys would sometimes crash because RedisToGo was tripping up the deploy. Developers trying to use our app might have better luck with the official Redis addon.

Application Error

Hello,

I tried to deploy this code on Heroku, but it showed me an Application Error. "

2016-03-07T00:17:16.446416+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=zakapp.herokuapp.com request_id=84706f2e-353c-4ad2-8885-8187f63303aa fwd="99.246.125.65" dyno= connect= service= status=503 bytes=

2016-03-07T00:17:10+00:00 app[heroku-redis]: source=REDIS sample#active-connections=1 sample#load-avg-1m=0.325 sample#load-avg-5m=0.33 sample#load-avg-15m=0.24 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15405632.0kB sample#memory-free=13360600.0kB sample#memory-cached=527152kB sample#memory-redis=294048bytes sample#hit-rate=1 sample#evicted-keys=0

2016-03-07T00:17:31.687322+00:00 heroku[worker.1]: State changed from crashed to starting

2016-03-07T00:17:34.624612+00:00 heroku[worker.1]: Starting process with command celery -A reminders.celery worker -l info

2016-03-07T00:17:35.237161+00:00 heroku[worker.1]: State changed from starting to up

2016-03-07T00:17:36.373802+00:00 app[worker.1]: Traceback (most recent call last):

2016-03-07T00:17:36.373819+00:00 app[worker.1]: File "/app/.heroku/python/bin/celery", line 7, in
2016-03-07T00:17:36.373970+00:00 app[worker.1]: from celery import five

2016-03-07T00:17:36.373972+00:00 app[worker.1]: File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/init.py", line 19, in

2016-03-07T00:17:36.373974+00:00 app[worker.1]: from uuid import UUID, uuid4 as _uuid4, _uuid_generate_random

2016-03-07T00:17:36.374010+00:00 app[worker.1]: ImportError: cannot import name _uuid_generate_random

2016-03-07T00:17:37.174982+00:00 heroku[worker.1]: State changed from up to crashed

2016-03-07T00:17:37.145990+00:00 heroku[worker.1]: Process exited with status 1

Thanks,
Adesh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.