Let's help people find houses nearby that are planned to be demolished and share health tips via SMS.
Try it by texting a street address in Detroit to 313-254-DEMO (aka 313-254-3366). A street address should look like "9385 E Vernor" or "2 Woodward", no need to include the city, state or zip code.
We locate the address you send us against our geocoder and then populate the text response by querying two datasets on our Open Data Portal:
- Upcoming Demolitions: Properties with a contractor and scheduled knock-down date
- Demolition Pipeline: Properties with a completed asbestos abatement survey and projected for demo within the year
We'll text you back with information about whether or not nearby houses are planned for demolition. "Nearby" is within 500ft, or about 1.5 blocks. You can opt-into notifications three days before houses nearby are scheduled to be knocked down.
If you call this number, we'll play back an instructional voice recording.
Requires Python 3.6
git clone https://github.com/CityOfDetroit/demo-alerts.git cd demo-alerts pip install -r requirements.txt
We store our subscribers in a SQLite database. Create a
subscribers table like so:
import sqlite3 conn = sqlite3.connect("db/sample.sqlite") c = conn.cursor() c.execute("CREATE TABLE subscribers (active integer, phone text, matched_address text, location text, subscribed_date text, last_alert_date text)") conn.commit() conn.close()
The SQLite Manager extension for Firefox is handy here.
.envand add your secrets. We have autoenv installed to auto-execute this file
python main.pyto start the server
- Download ngrok. In another terminal tab, change directories to your unzipped download and run
./ngrok http <your-port-number>to forward the server to
- Login to Twilio. Go to Console > Phone Numbers.
- Set Messaging to "Configure with Webhooks, or TwiML Bins or Functions" and "A Message Comes In" to your ngrok webhook
- Set Voice & Fax to "Configure with Webhooks, or TwiML Bins or Functions" and "A Call Comes In" to a TwiML Bin (twilio.com/console/dev-tools/twiml-bins) that looks something like this:
<?xml version="1.0" encoding="UTF-8"?> <Response> <Play>https://some-file.mp3</Play> </Response>
- Text or call your number to trigger the Express app!
Send the alerts
Once a day, we want to send our active subsribers a notice if there are demos scheduled nearby them in the next three days.
In development, you can just run:
For production, we shedule this to run as a cron job on a remote Linux server:
/path/to/with your full directories
send_alerts.pywith the full path to your database, around line 16
- Add a new cron task:
- Configure the job to run at 11am every day and log errors to a local file:
0 11 * * * /bin/bash /path/to/demo-alerts/daily-alerts-twilio.sh >> /path/to/cron-output.log 2>&1
- List all cron jobs to confirm it's scheduled: