Skip to content

Simplify setup with file instead of Environment Variables #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ wheels/
.installed.cfg
*.egg
MANIFEST
Pipfile*

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -103,3 +104,5 @@ venv.bak/
# mypy
.mypy_cache/
.idea

secrets.py
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,12 @@ As members of the Python guild, you will be working through the challenges of Tw

We assume that before you begin, you will have [Python](http://www.python.org/) and [pip](http://www.pip-installer.org/en/latest/) installed on your system and available at the command line.

Before you can run this project, you will need to set three system environment variables. These are:
Before you can run this project, you will need to make a copy of secrets.py.example and name it secrets.py. Edit secrets.py and change the string values as follows, and then save the file:

* `TWILIO_ACCOUNT_SID` : [Get it from your Twilio Console](https://www.twilio.com/console).
* `TWILIO_AUTH_TOKEN` : Same as above.
* `TWILIO_PHONE_NUMBER` : A Twilio number that you own, that can be used for making calls and sending messages. You can find a list of phone numbers you control (and buy another one, if necessary) [in the console](https://www.twilio.com/console/phone-numbers/incoming).

For Mac and Linux, environment variables can be set by opening a terminal window and typing the following three commands - replace all the characters after the `=` with values from your Twilio account:
```
export TWILIO_ACCOUNT_SID=ACXXXXXXXXX
export TWILIO_AUTH_TOKEN=XXXXXXXXX
export TWILIO_PHONE_NUMBER=+16518675309
```
On Windows, the easiest way to set permanent environment variables (as of Windows 8) is using the `setx` command. Note that there is no `=`, just the key and value separated by a space:
```
setx TWILIO_ACCOUNT_SID ACXXXXXXXXX
setx TWILIO_AUTH_TOKEN XXXXXXXXX
setx TWILIO_PHONE_NUMBER +16518675309
```
## Running the application

1. Clone this repository. Navigate to the folder with the source code on your machine in a terminal window.
Expand Down
10 changes: 7 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
from twilio.rest import Client

# Pull in configuration from system environment variables
TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
TWILIO_PHONE_NUMBER = os.environ.get('TWILIO_PHONE_NUMBER')
#TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID')
#TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN')
#TWILIO_PHONE_NUMBER = os.environ.get('TWILIO_PHONE_NUMBER')
try:
from secrets import TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_PHONE_NUMBER
except ImportError:
print("Please create a secrets.py that looks like secrets.py.example")

# create an authenticated client that can make requests to Twilio for your
# account.
Expand Down
3 changes: 3 additions & 0 deletions secrets.py.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TWILIO_ACCOUNT_SID="ACXXXXXXXXX"
TWILIO_AUTH_TOKEN="XXXXXXXXX"
TWILIO_PHONE_NUMBER="+16518675309"