Twilio raffle manager



Please leave your comments and suggestions. Feedback and pull requests are very welcome.

This is a raffle manager.

Let's say you run a local meetup, and every meetup you raffle a prize to your participants. This app is supposed to help you keep track of your raffles and participants, using Twilio to handle the communication.

How it works

The raffle home is in /. From there, participants find the number they have to text to enter the raffle.

The background image used on the raffle home is /static/images/cover.png. The one in the repo is from WOCin Tech Chat and it is free to use.

The Admin page is /admin.

Some rules

Improvements to come soon

Running locally

For this app, you will need Mailgun and Twilio.

  1. API Key
  2. Sandbox Domain URL (should look like "sandboxc6235728hdkjehf283hajf13a90679.mailgun.org" Both of these pieces of information can be found on the landing page of the Mailgun control panel.

Now that you have everything you need, we will keep your precious keys and number as environment variables.

Your SECRET_KEY is not from any external service. It is like a password. Use any password you want.

$ export TWILIO_NUMBER="+55555555555"

Note that the "export" is limited to the Terminal window you have open. You have to re-export every time you open a new window. (If this gets frustrating, see if you can figure out autoenv.)

$ psql
create database raffle;

$ sudo pip install -r requirements.txt

$ python create_models.py

It will ask you for your email to create the first Admin user. Copy the temporary password given. You will need that to login and have access to /admin

You're good to go.

In case you want to populate the database with some data to make testing easier, you can run populate.py.

$ python populate.py

It will create an active, a closed, and an upcoming raffle. All of them with 50 bogus participants.

Deploying it to Heroku

$ heroku login
Enter your Heroku credentials.
Email: your@email.com
Authentication successful.

$ heroku apps:create your_app_name

Basically what happens here is that now you have one more remote git repo. If you list ou remote repos, you will see your Github and your Heroku repos:

$ git remote -v

Now every time you push something to Github with git push, you will have to push again to Heroku with git push heroku if you want it deployed. You can setup a Github/Heroku integration if you want to automate this process.

$ heroku config:add SECRET_KEY="YOUR_SECRET_KEY"
$ heroku config:set MAILGUN_API_KEY="YOUR_API_KEY"
$ heroku config:set TWILIO_NUMBER="+55555555555"

$ heroku config:add TZ="YOUR_TIME_ZONE"

This is important because the raffles are time based. If you don't set it right, they won't work as expected.

Now, enable the PostgreSQL addon. This level is free but does have size and speed limitations (more details). https://elements.heroku.com/addons/heroku-postgresql

$ heroku addons:create heroku-postgresql:hobby-dev

When you've done this you should notice that it sets a variable on Heroku called DATABASE_URL. Check with heroku config.

$ heroku config

This variable is in app.py:

app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'postgresql://localhost/raffle')
db = SQLAlchemy(app)

It means that when you run app.py locally, it will look for DATABASE_URL, fail, then look for the database on localhost.

$ git push heroku

The response will look like this:

Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 373 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: -----> Using set buildpack heroku/python
remote: -----> Python app detected
remote: -----> Installing dependencies with pip
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: -----> Compressing... done, 41.4MB
remote: -----> Launching... done, v18
remote:        https://your_app_name.herokuapp.com/ deployed to Heroku
remote: Verifying deploy... done.

https://your_app_name.herokuapp.com/ is your URL. But you're still have need to create te tables.

$ heroku run python create_models.py

Same thing: It will ask you for your email to create the first Admin user. Copy the temporary password given. You will need that to login and have access to /admin.

Now you're good to go: https://your_app_name.herokuapp.com/login

If you want to populate the database:

$ heroku run python populate.py

Happy raffles!

Special thanks to Jennie Lees. Good chuncks of this documentation have been written based on her tutorials. Visit her portfolio: http://jennielees.github.io.