From bd1d582c8b0ac888836c2a32c32acee52182d81e Mon Sep 17 00:00:00 2001 From: Giovani Date: Wed, 28 Jul 2021 17:24:58 -0400 Subject: [PATCH] feat: add ability to load env vars from file --- pyvis.py | 13 ++++++++++--- requirements.txt | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyvis.py b/pyvis.py index 3a5e1eb..e1a1f44 100644 --- a/pyvis.py +++ b/pyvis.py @@ -2,6 +2,13 @@ import discord import requests import json import os +from dotenv import load_dotenv + +# load environment variables +load_dotenv() +DISCORD_BOT_TOKEN = os.getenv('DISCORD_BOT_TOKEN') +DISCORD_GUILD = os.getenv('DISCORD_GUILD') +LUNAR_CRUSH_API_KEY = os.getenv('LUNAR_CRUSH_API_KEY') client = discord.Client() @@ -22,11 +29,11 @@ async def on_message(message): await message.channel.send("Some resources for you here!") # Crypto command - if msg_str == "!crypto": + if msg_str.startswith("!crypto"): symbols = ["BTC", "ETH", "LTC"] # make the call for prices - http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + os.getenv("LUNAR_CRUSH_API_KEY") + "&symbol=" + ",".join(symbols)) + http_response = requests.get("https://api.lunarcrush.com/v2?data=assets&key=" + LUNAR_CRUSH_API_KEY + "&symbol=" + ",".join(symbols)) data = json.loads(http_response.text) # extract prices @@ -42,4 +49,4 @@ async def on_message(message): await message.channel.send(msg_response) -client.run(os.getenv("DISCORD_BOT_TOKEN")) # pass the bot token here \ No newline at end of file +client.run(DISCORD_BOT_TOKEN) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0a809eb..df177f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ charset-normalizer==2.0.3 discord.py==1.7.3 idna==3.2 multidict==5.1.0 +python-dotenv==0.19.0 requests==2.26.0 typing-extensions==3.10.0.0 urllib3==1.26.6