Be notified on Discord when you receive a PyTrick from the Real Python newsletter.
PyTricks are short python snippets sent to your email inbox by the Real Python team. If you haven't done so, you can subscribe to their newsletter here.
This script fetches the PyTricks you receive on the Gmail API and sends them to a Discord server.

- a Gmail address subscribed to the Real Python newsletter
- python3 (version > 3.6)
- python3-pip
- Clone the repository:
git clone https://github.com/meroupatate/pytricks-discord-bot.git- Install the python dependencies:
cd pytricks-discord-bot
pip3 install -r requirements.txt- Follow the Python Quickstart tutorial to get you Gmail API credentials:
- Enable the Gmail API
- Save your credentials.json file
- Copy the script quickstart.py and make sure to allow read AND write operations by replacing the line
SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
by
SCOPES = ['https://www.googleapis.com/auth/gmail.modify']
(this script won't work as expected if it has no write permissions)
- Run the modified quickstart.py on a machine with a web browser and give the required authorizations when they ask you to
This script should generate a
token.picklefile that you will need to connect to the Gmail API.
- Once done with the steps above, put
token.picklein the git repository you previously cloned:
mv token.pickle /path/to/pytricks-discord-bot- Edit
.env.exampleand replace the link with a webhook from your Discord server (click here for more information on how to create your webhook):
mv .env.example .env
vim .env
# DISCORD_WEBHOOK = 'https://discordapp.com/api/webhooks/xxxx/yyyyyyy'- If everything went fine, you should now be able to run
python get_tricks.py. You can keep it running by creating a dedicated systemd service:
An example of /etc/systemd/system/pytricks.service file for a cloned repository located at /home/patate/pytricks-discord-bot:
[Unit]
Description=PyTricks service
After=multi-user.target
[Service]
Type=idle
WorkingDirectory=/home/patate/pytricks-discord-bot/
ExecStart=/usr/bin/python3 /home/patate/pytricks-discord-bot/get_tricks.py
Restart=on-failure
RestartSec=60s
[Install]
WantedBy=multi-user.target
Start your service by running systemctl start pytricks.service and receive your PyTricks on Discord :D