Skip to content

Commit

Permalink
Remove unnecessary code from the Flask app in tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed May 19, 2020
1 parent e8b9d56 commit 03cc4d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 9 additions & 6 deletions tutorial/03-responding-to-slack-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ The code for this step is available [here](PythOnBoardingBot).
```
slackclient>=2.0.0
slackeventsapi>=2.1.0
Flask>=1.1.1
certifi
Flask>=1.1.2
```

> 💡 **[Certifi](https://github.com/certifi/python-certifi)** is a carefully curated collection of Root Certificates for validating the trustworthiness of SSL certificates while verifying the identity of TLS hosts. It has been extracted from the Requests project.
Expand All @@ -39,8 +38,6 @@ import logging
from flask import Flask
from slack import WebClient
from slackeventsapi import SlackEventAdapter
import ssl as ssl_lib
import certifi
from onboarding_tutorial import OnboardingTutorial
```

Expand Down Expand Up @@ -210,19 +207,25 @@ def message(payload):

Finally, we need to make our app runnable.

- 🏁 Add the following lines of code to the end of `app.py`.
- 🏁 Add the following lines of code to the end of `app.py` and run `FLASK_ENV=development python app.py`.

```Python
if __name__ == "__main__":
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
app.run(port=3000)
```

**Note:** When running in a virtual environment you often need to specify the location of the SSL Certificate(`cacert.pem`). To make this easy we use Certifi's built-in `where()` function to locate the installed certificate authority (CA) bundle.

```python
import ssl as ssl_lib
import certifi

ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
```

**Final Note:** If you're interested in learning how to modify this app to run asynchronously I've adapted this code as such [here](PythOnBoardingBot/async_app.py).

---
Expand Down
3 changes: 0 additions & 3 deletions tutorial/PythOnBoardingBot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from flask import Flask
from slack import WebClient
from slackeventsapi import SlackEventAdapter
import ssl as ssl_lib
import certifi
from onboarding_tutorial import OnboardingTutorial

# Initialize a Flask app to host the events adapter
Expand Down Expand Up @@ -146,5 +144,4 @@ def message(payload):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
ssl_context = ssl_lib.create_default_context(cafile=certifi.where())
app.run(port=3000)

0 comments on commit 03cc4d8

Please sign in to comment.